🇪🇸 A Spanish version of this guide is available below / Una versión en español de esta guía está disponible a continuación.
- App for a coffee shop
- Unlimited resources (💵💶💷💴) – no payment processing needed
- Infinite products can be added to the cart
- No user profile customisation
- Everything runs locally – no data is persisted between sessions
With Git:
git clone https://github.com/Beelzenef/workshop_flutter.git
cd workshop_flutter
git checkout workshopWithout Git:
Download the starter project directly from download-directory.github.io.
Open the app/ folder with Visual Studio Code or Android Studio, then run:
flutter pub get
flutter runAdd web support:
flutter create --platforms=web .Add Linux support:
flutter create --platforms=linux .Open lib/coffee_manager.dart. This file contains the CoffeeManager class which acts as a simple in-memory data store for the app. It holds:
- The logged-in
User - The list of
Productitems currently in the cart (productsInCart) - The list of completed
Orderobjects (orders) - A running cart
total
Feel free to customise the default user data.
In lib/main.dart, notice the MaterialApp widget. Set debugShowCheckedModeBanner: false to hide the red DEBUG ribbon. Use hot reload (press r in the terminal, or save the file in your editor) to see the change instantly.
Create the following files inside lib/pages/:
| File | Purpose |
|---|---|
catalog.dart |
Lists available coffee products |
cart.dart |
Shows items currently in the cart |
profile.dart |
Displays user information |
Each file should contain a StatefulWidget subclass with the matching name (e.g. CatalogPage).
In lib/main.dart, update HomePage to include a BottomNavigationBar with three tabs:
- Catalog – navigates to
CatalogPage - Cart – navigates to
CartPage - Profile – navigates to
ProfilePage
Use a switch statement (or if/else) to return the correct page widget based on the currently selected tab index.
Create the following files inside lib/models/:
| File | Class | Fields |
|---|---|---|
product.dart |
Product |
name (String), price (int), pic (String) |
user.dart |
User |
name (String), mail (String), phone (String) |
order.dart |
Order |
products (int), total (int), orderedAt (DateTime) |
- In
CatalogPage, read the product list and callCoffeeShopApp.manager.addToCart(product)when a tile is tapped. - In
CartPage, displayCoffeeShopApp.manager.productsInCartand provide PAY and REMOVE buttons that callmanager.makeOrder()andmanager.clearCart(). - In
ProfilePage, show the user's name, email, and phone. If there are completed orders, show a button that navigates to anOrdersPage.
- App para una cafetería
- Recursos (💵💶💷💴) ilimitados
- Se pueden añadir productos infinitos
- No hay personalización de user profile
- Todo ocurre en local
- No estamos almacenando state o datos
Si no sabes o no quieres usar Git, puedes descargar el proyecto desde esta web.
Añade soporte para web:
flutter create --platforms=web .
Añade soporte para Linux:
flutter create --platforms=linux .
Si usas git:
- Clona el proyecto en local
- Cambia a la branch
workshop
Abre con Visual Studio Code o Android Studio, a tu elección.
- Revisamos
coffee_manager.dart(y si queremos personalizamos contenido) - Eliminamos
demo modebanner, ¡es fácil implementar cambios conhot reload!
Añadimos páginas:
- Cart
- Catalog
- Profile
Ahora podemos implementar BottomNavigationBar. Así podemos ver la navegación, modificamos la página para ver que podemos crear cositas.
Añadimos modelos:
- User
- Order
- Product