Skip to content

Commit 50ea32c

Browse files
committed
flutter 2.1 migration
1 parent 633cb6e commit 50ea32c

File tree

8 files changed

+58
-32
lines changed

8 files changed

+58
-32
lines changed

flutter/app/lib/preset_store.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
5353
loadContentFromAssets().then(
5454
(value) => setState(() {
5555
_content = value;
56-
List<Product> products = List<Product>();
56+
List<Product> products = List<Product>.empty(growable: true);
5757

5858
List<dynamic> loadedProducts = value['products'];
5959

@@ -156,7 +156,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
156156
? generateMaterialColor(Colors.black)
157157
: Colors.purple)
158158
: Colors.purple,
159-
accentColor: Colors.deepOrange,
159+
//accentColor: Colors.deepOrange,
160160
textTheme: GoogleFonts.latoTextTheme(
161161
Theme.of(context).textTheme,
162162
),

flutter/app/lib/screens/auth_screen.dart

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class _AuthCardState extends State<AuthCard>
157157
),
158158
content: Text(message),
159159
actions: [
160-
FlatButton(
160+
TextButton(
161161
onPressed: () {
162162
Navigator.of(ctx).pop();
163163
},
@@ -262,6 +262,8 @@ class _AuthCardState extends State<AuthCard>
262262
if (value.isEmpty || !value.contains('@')) {
263263
return 'Invalid email!';
264264
}
265+
266+
return null;
265267
},
266268
onSaved: (value) {
267269
_authData['email'] = value;
@@ -275,6 +277,8 @@ class _AuthCardState extends State<AuthCard>
275277
if (value.isEmpty || value.length < 5) {
276278
return 'Password is too short!';
277279
}
280+
281+
return null;
278282
},
279283
onSaved: (value) {
280284
_authData['password'] = value;
@@ -302,6 +306,8 @@ class _AuthCardState extends State<AuthCard>
302306
if (value != _passwordController.text) {
303307
return 'Passwords do not match!';
304308
}
309+
310+
return null;
305311
}
306312
: null,
307313
),
@@ -314,25 +320,40 @@ class _AuthCardState extends State<AuthCard>
314320
if (_isLoading)
315321
CircularProgressIndicator()
316322
else
317-
RaisedButton(
318-
child:
319-
Text(_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'),
323+
ElevatedButton(
324+
child: Padding(
325+
padding: const EdgeInsets.symmetric(
326+
horizontal: 30.0, vertical: 8.0),
327+
child: Text(
328+
_authMode == AuthMode.Login ? 'LOGIN' : 'SIGN UP'),
329+
),
320330
onPressed: _submit,
321-
shape: RoundedRectangleBorder(
322-
borderRadius: BorderRadius.circular(30),
331+
style: ElevatedButton.styleFrom(
332+
shape: RoundedRectangleBorder(
333+
borderRadius: BorderRadius.circular(30),
334+
),
335+
primary:
336+
Theme.of(context).primaryColor, // Background color
337+
338+
onPrimary: Theme.of(context)
339+
.primaryTextTheme
340+
.button
341+
.color, // Text Color (Foreground color)
323342
),
324-
padding:
325-
EdgeInsets.symmetric(horizontal: 30.0, vertical: 8.0),
326-
color: Theme.of(context).primaryColor,
327-
textColor: Theme.of(context).primaryTextTheme.button.color,
328343
),
329-
FlatButton(
330-
child: Text(
331-
'${_authMode == AuthMode.Login ? 'SIGNUP' : 'LOGIN'} INSTEAD'),
344+
TextButton(
345+
child: Padding(
346+
padding: const EdgeInsets.symmetric(
347+
horizontal: 30.0, vertical: 4),
348+
child: Text(
349+
'${_authMode == AuthMode.Login ? 'SIGNUP' : 'LOGIN'} INSTEAD'),
350+
),
332351
onPressed: _switchAuthMode,
333-
padding: EdgeInsets.symmetric(horizontal: 30.0, vertical: 4),
334-
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
335-
textColor: Theme.of(context).primaryColor,
352+
style: TextButton.styleFrom(
353+
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
354+
primary: Theme.of(context)
355+
.primaryColor, // Text Color (Foreground color)
356+
),
336357
),
337358
],
338359
),

flutter/app/lib/screens/cart_screen.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class _OrderButtonState extends State<OrderButton> {
8383
var _isLoading = false;
8484
@override
8585
Widget build(BuildContext context) {
86-
return FlatButton(
86+
return TextButton(
8787
onPressed: (widget.cart.totalAmount <= 0 || _isLoading)
8888
? null
8989
: () async {
@@ -105,7 +105,10 @@ class _OrderButtonState extends State<OrderButton> {
105105
Navigator.of(context).pushNamed(CheckoutScreen.routeName);
106106
},
107107
child: _isLoading ? CircularProgressIndicator() : Text('ORDER NOW'),
108-
textColor: Theme.of(context).primaryColor,
108+
style: TextButton.styleFrom(
109+
primary:
110+
Theme.of(context).primaryColor, // Text Color (Foreground color)
111+
),
109112
);
110113
}
111114
}

flutter/app/lib/screens/checkout_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class _CheckoutState extends State<CheckoutScreen> {
212212
),
213213
SizedBox(height: 12),
214214
if (!_submitted)
215-
FlatButton(
215+
TextButton(
216216
child: Text(
217217
'Place your order',
218218
style: TextStyle(

flutter/app/lib/screens/edit_product_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class _EditProductScreenState extends State<EditProductScreen> {
114114
title: Text('An error occurred!'),
115115
content: Text('Something went wrong.'),
116116
actions: [
117-
FlatButton(
117+
TextButton(
118118
onPressed: () {
119119
Navigator.of(ctx).pop();
120120
},

flutter/app/lib/widgets/badge.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Badge extends StatelessWidget {
2626
// color: Theme.of(context).accentColor,
2727
decoration: BoxDecoration(
2828
borderRadius: BorderRadius.circular(10.0),
29-
color: color != null ? color : Theme.of(context).accentColor,
29+
color: color != null ? color : Theme.of(context).primaryColor,
3030
),
3131
constraints: BoxConstraints(
3232
minWidth: 16,

flutter/app/lib/widgets/cart_item.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class CartItem extends StatelessWidget {
4545
'Do you want to remove the item from the cart?',
4646
),
4747
actions: [
48-
FlatButton(
48+
TextButton(
4949
onPressed: () => Navigator.of(ctx).pop(false),
5050
child: Text('No')),
51-
FlatButton(
51+
TextButton(
5252
onPressed: () => Navigator.of(ctx).pop(true),
5353
child: Text('Yes')),
5454
],

flutter/app/lib/widgets/product_item.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ProductItem extends StatelessWidget {
3535
onPressed: () {
3636
product.toggleFavoriteStatus(authData.token, authData.userId);
3737
},
38-
color: Theme.of(context).accentColor,
38+
color: Colors.white70,
3939
),
4040
),
4141
title: Text(
@@ -46,18 +46,20 @@ class ProductItem extends StatelessWidget {
4646
icon: Icon(Icons.shopping_cart),
4747
onPressed: () {
4848
cart.addItem(product.id, product.price, product.title);
49-
Scaffold.of(context).hideCurrentSnackBar();
50-
Scaffold.of(context).showSnackBar(
49+
ScaffoldMessenger.of(context).hideCurrentSnackBar();
50+
ScaffoldMessenger.of(context).showSnackBar(
5151
SnackBar(
5252
content: Text('Added item to cart!'),
5353
duration: Duration(seconds: 2),
54-
action: SnackBarAction(label: 'UNDO', onPressed: () {
55-
cart.removeSigleItem(product.id);
56-
}),
54+
action: SnackBarAction(
55+
label: 'UNDO',
56+
onPressed: () {
57+
cart.removeSigleItem(product.id);
58+
}),
5759
),
5860
);
5961
},
60-
color: Theme.of(context).accentColor,
62+
color: Colors.white70,
6163
),
6264
),
6365
),

0 commit comments

Comments
 (0)