Skip to content

Commit ea255fd

Browse files
committed
Flutter 3 Upgrade
1 parent 50ea32c commit ea255fd

26 files changed

+456
-380
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

22
ios/MobileOrders/MobileOrders.xcodeproj/project.xcworkspace/xcuserdata/jacobilin.xcuserdatad/UserInterfaceState.xcuserstate
3+
flutter/.DS_Store

flutter/app/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
/build/
3232

3333
# Web related
34-
lib/generated_plugin_registrant.dart
3534

3635
# Symbolication related
3736
app.*.symbols

flutter/app/assets/store.glowbom

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"title":"Store App","main_color":"Black","show_percentage_result":true,"voice":false,"show_number_result":true,"start_over":"","payment_link":"","conclusion":"Thank you! Please enter your shipping information:","products":[{"id":"p1","title":"Chair","description":"Introducing our luxurious and comfortable chair, designed to add a touch of elegance to any room in your home or office. Made with high-quality materials, this chair features plush cushioning for maximum comfort and support. The sleek and modern design adds sophistication and style to any interior decor, making it the perfect statement piece to elevate your space. ","price":29.99,"imageUrl":"https://picsum.photos/640","isFavorite":false},{"id":"p2","title":"Couch","description":"Perfect for lounging and relaxing in style, our luxurious couch is the epitome of comfort and sophistication. Made with high-quality materials and expert craftsmanship, this couch features plush cushions that provide the perfect balance of support and softness. Its modern and elegant design effortlessly adds a touch of class to any living room or den. ","price":59.99,"imageUrl":"https://picsum.photos/641","isFavorite":false},{"id":"p3","title":"Table","description":"Upgrade your home decor game with our stunning and practical table. Crafted with high-quality materials, this table boasts a modern design that effortlessly blends with any setting. Its spacious tabletop provides ample space for all your essentials, while the sturdy base ensures lasting durability and stability.","price":19.99,"imageUrl":"https://picsum.photos/639","isFavorite":false},{"id":"p4","title":"Bed","description":"Experience the ultimate in comfort and luxury with our expertly crafted bedding. Our plush and cozy bed features a premium mattress that conforms to your body, providing unparalleled support and relief from nighttime discomfort. The soft, breathable sheets and silky-smooth duvet cover create the perfect sleep sanctuary, while the hypoallergenic materials ensure a healthier and more relaxing sleep. ","price":49.99,"imageUrl":"https://picsum.photos/642","isFavorite":false}],"dnsgs":true}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class HttpException implements Exception {
2-
final String message;
2+
final String? message;
33

44
HttpException(this.message);
55

66
@override
77
String toString() {
8-
return message;
8+
return message!;
99
}
1010
}

flutter/app/lib/preset_store.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void main() {
2525
}
2626

2727
class MobileOrdersApp extends StatefulWidget {
28-
static String title = 'Mobile Orders';
28+
static String? title = 'Mobile Orders';
2929
final dynamic content;
3030
final bool onlyEditor;
3131
MobileOrdersApp(this.content, this.onlyEditor);
@@ -117,7 +117,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
117117
ChangeNotifierProvider(
118118
create: (ctx) => Auth(),
119119
),
120-
ChangeNotifierProxyProvider<Auth, Products>(
120+
ChangeNotifierProxyProvider<Auth, Products?>(
121121
create: (ctx) => null,
122122
update: (ctx, auth, previousProducts) => Products(
123123
auth.token,
@@ -128,7 +128,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
128128
ChangeNotifierProvider(
129129
create: (ctx) => Cart(),
130130
),
131-
ChangeNotifierProxyProvider<Auth, Orders>(
131+
ChangeNotifierProxyProvider<Auth, Orders?>(
132132
create: (ctx) => null,
133133
update: (ctx, auth, previousOrders) => Orders(
134134
auth.token,
@@ -139,7 +139,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
139139
],
140140
child: Consumer<Auth>(
141141
builder: (ctx, auth, _) => MaterialApp(
142-
title: MobileOrdersApp.title,
142+
title: MobileOrdersApp.title!,
143143
theme: ThemeData(
144144
primarySwatch: _content != null
145145
? (_content['main_color'] == 'Blue'

flutter/app/lib/providers/auth.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import 'package:shared_preferences/shared_preferences.dart';
1010
class Auth with ChangeNotifier {
1111
static const _key = 'FIREBASE_WEB_API_KEY';
1212
static const URL = 'FIREBASE_IO_URL';
13-
String _token;
14-
DateTime _expiryDate;
15-
String _userId;
16-
Timer _authTimer;
13+
String? _token;
14+
DateTime? _expiryDate;
15+
String? _userId;
16+
Timer? _authTimer;
1717

1818
bool _authRequired = false;
1919

20-
String get userId {
20+
String? get userId {
2121
return _userId;
2222
}
2323

24-
String get token {
24+
String? get token {
2525
if (_expiryDate != null &&
26-
_expiryDate.isAfter(DateTime.now()) &&
26+
_expiryDate!.isAfter(DateTime.now()) &&
2727
_token != null) {
2828
return _token;
2929
}
@@ -40,7 +40,7 @@ class Auth with ChangeNotifier {
4040
}
4141

4242
Future<void> _authenticate(
43-
String email, String password, String urlSegment) async {
43+
String? email, String? password, String urlSegment) async {
4444
final url =
4545
'https://identitytoolkit.googleapis.com/v1/accounts:$urlSegment?key=$_key';
4646
try {
@@ -73,7 +73,7 @@ class Auth with ChangeNotifier {
7373
{
7474
'token': _token,
7575
'userId': _userId,
76-
'expiryDate': _expiryDate.toIso8601String(),
76+
'expiryDate': _expiryDate!.toIso8601String(),
7777
},
7878
);
7979
prefs.setString('userData', userData);
@@ -89,26 +89,26 @@ class Auth with ChangeNotifier {
8989
}
9090

9191
final extractedUserData =
92-
json.decode(prefs.getString('userData')) as Map<String, Object>;
93-
final expiryDate = DateTime.parse(extractedUserData['expiryDate']);
92+
json.decode(prefs.getString('userData')!) as Map<String, Object>;
93+
final expiryDate = DateTime.parse(extractedUserData['expiryDate'] as String);
9494

9595
if (expiryDate.isBefore(DateTime.now())) {
9696
return false;
9797
}
9898

99-
_token = extractedUserData['token'];
99+
_token = extractedUserData['token'] as String?;
100100
_expiryDate = expiryDate;
101-
_userId = extractedUserData['userId'];
101+
_userId = extractedUserData['userId'] as String?;
102102
notifyListeners();
103103
_autoLogout();
104104
return true;
105105
}
106106

107-
Future<void> signup(String email, String password) async {
107+
Future<void> signup(String? email, String? password) async {
108108
return _authenticate(email, password, 'signUp');
109109
}
110110

111-
Future<void> signin(String email, String password) async {
111+
Future<void> signin(String? email, String? password) async {
112112
return _authenticate(email, password, 'signInWithPassword');
113113
}
114114

@@ -117,7 +117,7 @@ class Auth with ChangeNotifier {
117117
_userId = null;
118118
_expiryDate = null;
119119
if (_authTimer != null) {
120-
_authTimer.cancel();
120+
_authTimer!.cancel();
121121
}
122122
notifyListeners();
123123

@@ -127,10 +127,10 @@ class Auth with ChangeNotifier {
127127

128128
void _autoLogout() {
129129
if (_authTimer != null) {
130-
_authTimer.cancel();
130+
_authTimer!.cancel();
131131
}
132132

133-
final timerToExpiry = _expiryDate.difference(DateTime.now()).inSeconds;
133+
final timerToExpiry = _expiryDate!.difference(DateTime.now()).inSeconds;
134134
_authTimer = Timer(Duration(seconds: timerToExpiry), logout);
135135
}
136136
}

flutter/app/lib/providers/cart.dart

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import 'package:flutter/material.dart';
22

33
class CartItem {
4-
final String id;
5-
final String title;
6-
final int quantity;
7-
final double price;
4+
final String? id;
5+
final String? title;
6+
final int? quantity;
7+
final double? price;
88

99
CartItem({
10-
@required this.id,
11-
@required this.title,
12-
@required this.quantity,
13-
@required this.price,
10+
required this.id,
11+
required this.title,
12+
required this.quantity,
13+
required this.price,
1414
});
1515
}
1616

1717
class Cart with ChangeNotifier {
18-
Map<String, CartItem> _items = {};
18+
Map<String?, CartItem> _items = {};
1919

20-
Map<String, CartItem> get items {
20+
Map<String?, CartItem> get items {
2121
return {..._items};
2222
}
2323

@@ -28,15 +28,15 @@ class Cart with ChangeNotifier {
2828
double get totalAmount {
2929
var total = 0.0;
3030
_items.forEach((key, value) {
31-
total += value.price * value.quantity;
31+
total += value.price! * value.quantity!;
3232
});
3333
return total;
3434
}
3535

3636
void addItem(
37-
String productId,
38-
double price,
39-
String title,
37+
String? productId,
38+
double? price,
39+
String? title,
4040
) {
4141
if (_items.containsKey(productId)) {
4242
_items.update(
@@ -45,7 +45,7 @@ class Cart with ChangeNotifier {
4545
id: value.id,
4646
title: value.title,
4747
price: value.price,
48-
quantity: value.quantity + 1,
48+
quantity: value.quantity! + 1,
4949
),
5050
);
5151
} else {
@@ -63,23 +63,23 @@ class Cart with ChangeNotifier {
6363
notifyListeners();
6464
}
6565

66-
void removeItem(String productId) {
66+
void removeItem(String? productId) {
6767
_items.remove(productId);
6868
notifyListeners();
6969
}
7070

71-
void removeSigleItem(String productId) {
71+
void removeSigleItem(String? productId) {
7272
if (!_items.containsKey(productId)) {
7373
return;
7474
}
7575

76-
if (_items[productId].quantity > 1) {
76+
if (_items[productId]!.quantity! > 1) {
7777
_items.update(
7878
productId,
7979
(value) => CartItem(
8080
id: value.id,
8181
title: value.title,
82-
quantity: value.quantity - 1,
82+
quantity: value.quantity! - 1,
8383
price: value.price,
8484
),
8585
);

flutter/app/lib/providers/orders.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ import './cart.dart';
77
import 'auth.dart';
88

99
class OrderItem {
10-
final String id;
11-
final double amount;
10+
final String? id;
11+
final double? amount;
1212
final List<CartItem> products;
1313
final DateTime dateTime;
1414

1515
OrderItem({
16-
@required this.id,
17-
@required this.amount,
18-
@required this.products,
19-
@required this.dateTime,
16+
required this.id,
17+
required this.amount,
18+
required this.products,
19+
required this.dateTime,
2020
});
2121
}
2222

2323
class Orders with ChangeNotifier {
2424
List<OrderItem> _orders = [];
25-
final String authToken;
26-
final String userId;
25+
final String? authToken;
26+
final String? userId;
2727

2828
Orders(this.authToken, this.userId, this._orders);
2929

@@ -39,7 +39,7 @@ class Orders with ChangeNotifier {
3939
final url = Auth.URL + '/orders/$userId.json?auth=$authToken';
4040
try {
4141
final response = await http.get(Uri.parse(url));
42-
final extractedData = json.decode(response.body) as Map<String, dynamic>;
42+
final extractedData = json.decode(response.body) as Map<String, dynamic>?;
4343
if (extractedData == null) {
4444
return;
4545
}

flutter/app/lib/providers/product.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import 'package:http/http.dart' as http;
66
import 'auth.dart';
77

88
class Product with ChangeNotifier {
9-
final String id;
10-
final String title;
11-
final String description;
12-
final double price;
13-
final String imageUrl;
14-
bool isFavorite;
9+
final String? id;
10+
final String? title;
11+
final String? description;
12+
final double? price;
13+
final String? imageUrl;
14+
bool? isFavorite;
1515

1616
Product({
17-
@required this.id,
18-
@required this.title,
19-
@required this.description,
20-
@required this.price,
21-
@required this.imageUrl,
17+
required this.id,
18+
required this.title,
19+
required this.description,
20+
required this.price,
21+
required this.imageUrl,
2222
this.isFavorite = false,
2323
});
2424

@@ -33,9 +33,9 @@ class Product with ChangeNotifier {
3333
};
3434
}
3535

36-
Future<void> toggleFavoriteStatus(String token, String userId) async {
36+
Future<void> toggleFavoriteStatus(String? token, String? userId) async {
3737
final oldStatus = isFavorite;
38-
isFavorite = !isFavorite;
38+
isFavorite = !isFavorite!;
3939
notifyListeners();
4040

4141
if (token != null) {

0 commit comments

Comments
 (0)