Skip to content

Commit 8ee8bcf

Browse files
committed
⚙️ Set up (workshop)
1 parent 72c0218 commit 8ee8bcf

14 files changed

Lines changed: 180 additions & 81 deletions

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# A workshop in Flutter
22

3-
Let's create an app with Flutter
3+
Let's create an app with Flutter!
4+
5+
[![Flutter CI](https://github.com/Beelzenef/workshop_flutter/actions/workflows/dart.yaml/badge.svg)](https://github.com/Beelzenef/workshop_flutter/actions/workflows/dart.yaml)
46

57
## Requirements:
68

79
### Required:
810

9-
- BYOD
11+
- Bring Your Own Device (BYOD)
1012
- Basic/medium programming knowledge
1113
- Flutter SDK installed and set up
1214

@@ -19,8 +21,10 @@ To choose:
1921
2022
### Optional
2123

24+
To choose:
25+
2226
- Android emulator device
23-
- Physical device (developer mode enabled)
27+
- Physical device (developer mode and USB debugging enabled)
2428

2529
---
2630

@@ -32,14 +36,15 @@ Clone this repo and checkout to `workshop` branch.
3236

3337
General:
3438

35-
- [Build apps for any screen](https://flutter.dev/)
39+
- [Build apps for any screen with Flutter](https://flutter.dev/)
3640
- [Learn Flutter any way you want](https://flutter.dev/learn)
3741
- [Windows install](https://docs.flutter.dev/get-started/install/windows)
3842
- [A curated list of Flutter samples and apps](https://flutter.github.io/samples/#)
3943

4044
Android:
4145

4246
- [Create an android emulator and run your app](https://medium.com/@Narimane_hn/create-an-android-emulator-and-run-your-first-flutter-app-bdb914b63973)
47+
- [Run apps on a hardware device](https://developer.android.com/studio/run/device)
4348

4449
Dart:
4550

app/.metadata

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This file should be version controlled.
55

66
version:
7-
revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
7+
revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
88
channel: stable
99

1010
project_type: app
@@ -13,14 +13,11 @@ project_type: app
1313
migration:
1414
platforms:
1515
- platform: root
16-
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
17-
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
18-
- platform: android
19-
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
20-
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
16+
create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
17+
base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
2118
- platform: web
22-
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
23-
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
19+
create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
20+
base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
2421

2522
# User provided section
2623

app/README.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
11
# coffee_shop
22

3-
A new Flutter project.
4-
5-
## Getting Started
6-
7-
This project is a starting point for a Flutter application.
8-
9-
A few resources to get you started if this is your first Flutter project:
10-
11-
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
12-
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
13-
14-
For help getting started with Flutter development, view the
15-
[online documentation](https://docs.flutter.dev/), which offers tutorials,
16-
samples, guidance on mobile development, and a full API reference.
3+
A new Flutter app!

app/lib/coffee_manager.dart

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import 'package:coffee_shop/models/product.dart';
33
import 'package:coffee_shop/models/user.dart';
44

55
class CoffeeManager {
6-
final User yourUser = User(
7-
name: 'Your awesome name', mail: '[email protected]', phone: '666-666-66');
6+
final User user =
7+
User(name: 'Awesome', mail: '[email protected]', phone: '666-666-66');
88

99
final List<Product> productsInCart = [];
1010
final List<Order> orders = [];
@@ -13,27 +13,32 @@ class CoffeeManager {
1313

1414
void addToCart(Product product) {
1515
productsInCart.add(product);
16-
calculateTotal();
16+
_calculateTotal();
1717
}
1818

19-
void calculateTotal() {
20-
var prices = productsInCart.map((e) => e.price).toList();
21-
total = prices.reduce((value, element) => value + element);
19+
void _calculateTotal() {
20+
if (productsInCart.isNotEmpty) {
21+
var prices = productsInCart.map((e) => e.price).toList();
22+
total = prices.reduce((value, element) => value + element);
23+
} else {
24+
total = 0;
25+
}
2226
}
2327

2428
void makeOrder() {
25-
int howManyProducts = productsInCart.length;
29+
if (productsInCart.isNotEmpty) {
30+
int howManyProducts = productsInCart.length;
2631

27-
var newOrder = Order(
28-
products: howManyProducts,
29-
total: total,
30-
orderedAt: DateTime.now());
31-
orders.add(newOrder);
32+
var newOrder = Order(
33+
products: howManyProducts, total: total, orderedAt: DateTime.now());
34+
orders.add(newOrder);
3235

33-
clearCart();
36+
clearCart();
37+
}
3438
}
3539

3640
void clearCart() {
3741
productsInCart.clear();
42+
_calculateTotal();
3843
}
3944
}

app/lib/main.dart

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,39 @@ class CoffeeShopApp extends StatelessWidget {
1111
Widget build(BuildContext context) {
1212
return MaterialApp(
1313
debugShowCheckedModeBanner: false,
14-
title: 'Flutter Demo',
14+
title: 'CoffeeShop',
1515
theme: ThemeData(
1616
primarySwatch: Colors.blue,
1717
),
18-
home: const MyHomePage(title: 'Flutter Demo Home Page'),
18+
home: const MyHomePage(),
1919
);
2020
}
2121
}
2222

2323
class MyHomePage extends StatefulWidget {
24-
const MyHomePage({super.key, required this.title});
25-
26-
final String title;
24+
const MyHomePage({super.key});
2725

2826
@override
2927
State<MyHomePage> createState() => _MyHomePageState();
3028
}
3129

3230
class _MyHomePageState extends State<MyHomePage> {
33-
int _counter = 0;
34-
35-
void _incrementCounter() {
36-
setState(() {
37-
_counter++;
38-
});
39-
}
40-
4131
@override
4232
Widget build(BuildContext context) {
4333
return Scaffold(
4434
appBar: AppBar(
45-
title: Text(widget.title),
35+
title: const Text('My app'),
4636
),
47-
body: Center(
37+
body: const Center(
4838
child: Column(
4939
mainAxisAlignment: MainAxisAlignment.center,
5040
children: <Widget>[
51-
const Text(
52-
'You have pushed the button this many times:',
53-
),
5441
Text(
55-
'$_counter',
56-
style: Theme.of(context).textTheme.headlineMedium,
42+
'...',
5743
),
5844
],
5945
),
6046
),
61-
floatingActionButton: FloatingActionButton(
62-
onPressed: _incrementCounter,
63-
tooltip: 'Increment',
64-
child: const Icon(Icons.add),
65-
),
6647
);
6748
}
6849
}

app/pubspec.lock

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ packages:
55
dependency: transitive
66
description:
77
name: async
8-
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
8+
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "2.10.0"
11+
version: "2.11.0"
1212
boolean_selector:
1313
dependency: transitive
1414
description:
@@ -21,10 +21,10 @@ packages:
2121
dependency: transitive
2222
description:
2323
name: characters
24-
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
24+
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
2525
url: "https://pub.dev"
2626
source: hosted
27-
version: "1.2.1"
27+
version: "1.3.0"
2828
clock:
2929
dependency: transitive
3030
description:
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: collection
40-
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
40+
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.17.0"
43+
version: "1.17.1"
4444
cupertino_icons:
4545
dependency: "direct main"
4646
description:
@@ -79,10 +79,10 @@ packages:
7979
dependency: transitive
8080
description:
8181
name: js
82-
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
82+
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
8383
url: "https://pub.dev"
8484
source: hosted
85-
version: "0.6.5"
85+
version: "0.6.7"
8686
lints:
8787
dependency: transitive
8888
description:
@@ -95,10 +95,10 @@ packages:
9595
dependency: transitive
9696
description:
9797
name: matcher
98-
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
98+
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
9999
url: "https://pub.dev"
100100
source: hosted
101-
version: "0.12.13"
101+
version: "0.12.15"
102102
material_color_utilities:
103103
dependency: transitive
104104
description:
@@ -111,18 +111,18 @@ packages:
111111
dependency: transitive
112112
description:
113113
name: meta
114-
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
114+
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
115115
url: "https://pub.dev"
116116
source: hosted
117-
version: "1.8.0"
117+
version: "1.9.1"
118118
path:
119119
dependency: transitive
120120
description:
121121
name: path
122-
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
122+
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
123123
url: "https://pub.dev"
124124
source: hosted
125-
version: "1.8.2"
125+
version: "1.8.3"
126126
sky_engine:
127127
dependency: transitive
128128
description: flutter
@@ -172,10 +172,10 @@ packages:
172172
dependency: transitive
173173
description:
174174
name: test_api
175-
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
175+
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
176176
url: "https://pub.dev"
177177
source: hosted
178-
version: "0.4.16"
178+
version: "0.5.1"
179179
vector_math:
180180
dependency: transitive
181181
description:
@@ -185,4 +185,4 @@ packages:
185185
source: hosted
186186
version: "2.1.4"
187187
sdks:
188-
dart: ">=2.19.6 <3.0.0"
188+
dart: ">=3.0.0-0 <4.0.0"

app/test/widget_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// This is a basic Flutter widget test.
2+
//
3+
// To perform an interaction with a widget in your test, use the WidgetTester
4+
// utility in the flutter_test package. For example, you can send tap and scroll
5+
// gestures. You can also use WidgetTester to find child widgets in the widget
6+
// tree, read text, and verify that the values of widget properties are correct.
7+
8+
import 'package:flutter/material.dart';
9+
import 'package:flutter_test/flutter_test.dart';
10+
11+
import 'package:app/main.dart';
12+
13+
void main() {
14+
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15+
// Build our app and trigger a frame.
16+
await tester.pumpWidget(const MyApp());
17+
18+
// Verify that our counter starts at 0.
19+
expect(find.text('0'), findsOneWidget);
20+
expect(find.text('1'), findsNothing);
21+
22+
// Tap the '+' icon and trigger a frame.
23+
await tester.tap(find.byIcon(Icons.add));
24+
await tester.pump();
25+
26+
// Verify that our counter has incremented.
27+
expect(find.text('0'), findsNothing);
28+
expect(find.text('1'), findsOneWidget);
29+
});
30+
}

app/web/favicon.png

917 Bytes
Loading

app/web/icons/Icon-192.png

5.17 KB
Loading

app/web/icons/Icon-512.png

8.06 KB
Loading

0 commit comments

Comments
 (0)