Skip to content

Commit

Permalink
Flutter 3 Upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed May 20, 2023
1 parent 50ea32c commit ea255fd
Show file tree
Hide file tree
Showing 26 changed files with 456 additions and 380 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@

ios/MobileOrders/MobileOrders.xcodeproj/project.xcworkspace/xcuserdata/jacobilin.xcuserdatad/UserInterfaceState.xcuserstate
flutter/.DS_Store
1 change: 0 additions & 1 deletion flutter/app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols
Expand Down
1 change: 1 addition & 0 deletions flutter/app/assets/store.glowbom
Original file line number Diff line number Diff line change
@@ -0,0 +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}
4 changes: 2 additions & 2 deletions flutter/app/lib/model/http_exception.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
class HttpException implements Exception {
final String message;
final String? message;

HttpException(this.message);

@override
String toString() {
return message;
return message!;
}
}
8 changes: 4 additions & 4 deletions flutter/app/lib/preset_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
}

class MobileOrdersApp extends StatefulWidget {
static String title = 'Mobile Orders';
static String? title = 'Mobile Orders';
final dynamic content;
final bool onlyEditor;
MobileOrdersApp(this.content, this.onlyEditor);
Expand Down Expand Up @@ -117,7 +117,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
ChangeNotifierProvider(
create: (ctx) => Auth(),
),
ChangeNotifierProxyProvider<Auth, Products>(
ChangeNotifierProxyProvider<Auth, Products?>(
create: (ctx) => null,
update: (ctx, auth, previousProducts) => Products(
auth.token,
Expand All @@ -128,7 +128,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
ChangeNotifierProvider(
create: (ctx) => Cart(),
),
ChangeNotifierProxyProvider<Auth, Orders>(
ChangeNotifierProxyProvider<Auth, Orders?>(
create: (ctx) => null,
update: (ctx, auth, previousOrders) => Orders(
auth.token,
Expand All @@ -139,7 +139,7 @@ class _MobileOrdersAppState extends State<MobileOrdersApp> {
],
child: Consumer<Auth>(
builder: (ctx, auth, _) => MaterialApp(
title: MobileOrdersApp.title,
title: MobileOrdersApp.title!,
theme: ThemeData(
primarySwatch: _content != null
? (_content['main_color'] == 'Blue'
Expand Down
36 changes: 18 additions & 18 deletions flutter/app/lib/providers/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import 'package:shared_preferences/shared_preferences.dart';
class Auth with ChangeNotifier {
static const _key = 'FIREBASE_WEB_API_KEY';
static const URL = 'FIREBASE_IO_URL';
String _token;
DateTime _expiryDate;
String _userId;
Timer _authTimer;
String? _token;
DateTime? _expiryDate;
String? _userId;
Timer? _authTimer;

bool _authRequired = false;

String get userId {
String? get userId {
return _userId;
}

String get token {
String? get token {
if (_expiryDate != null &&
_expiryDate.isAfter(DateTime.now()) &&
_expiryDate!.isAfter(DateTime.now()) &&
_token != null) {
return _token;
}
Expand All @@ -40,7 +40,7 @@ class Auth with ChangeNotifier {
}

Future<void> _authenticate(
String email, String password, String urlSegment) async {
String? email, String? password, String urlSegment) async {
final url =
'https://identitytoolkit.googleapis.com/v1/accounts:$urlSegment?key=$_key';
try {
Expand Down Expand Up @@ -73,7 +73,7 @@ class Auth with ChangeNotifier {
{
'token': _token,
'userId': _userId,
'expiryDate': _expiryDate.toIso8601String(),
'expiryDate': _expiryDate!.toIso8601String(),
},
);
prefs.setString('userData', userData);
Expand All @@ -89,26 +89,26 @@ class Auth with ChangeNotifier {
}

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

if (expiryDate.isBefore(DateTime.now())) {
return false;
}

_token = extractedUserData['token'];
_token = extractedUserData['token'] as String?;
_expiryDate = expiryDate;
_userId = extractedUserData['userId'];
_userId = extractedUserData['userId'] as String?;
notifyListeners();
_autoLogout();
return true;
}

Future<void> signup(String email, String password) async {
Future<void> signup(String? email, String? password) async {
return _authenticate(email, password, 'signUp');
}

Future<void> signin(String email, String password) async {
Future<void> signin(String? email, String? password) async {
return _authenticate(email, password, 'signInWithPassword');
}

Expand All @@ -117,7 +117,7 @@ class Auth with ChangeNotifier {
_userId = null;
_expiryDate = null;
if (_authTimer != null) {
_authTimer.cancel();
_authTimer!.cancel();
}
notifyListeners();

Expand All @@ -127,10 +127,10 @@ class Auth with ChangeNotifier {

void _autoLogout() {
if (_authTimer != null) {
_authTimer.cancel();
_authTimer!.cancel();
}

final timerToExpiry = _expiryDate.difference(DateTime.now()).inSeconds;
final timerToExpiry = _expiryDate!.difference(DateTime.now()).inSeconds;
_authTimer = Timer(Duration(seconds: timerToExpiry), logout);
}
}
38 changes: 19 additions & 19 deletions flutter/app/lib/providers/cart.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import 'package:flutter/material.dart';

class CartItem {
final String id;
final String title;
final int quantity;
final double price;
final String? id;
final String? title;
final int? quantity;
final double? price;

CartItem({
@required this.id,
@required this.title,
@required this.quantity,
@required this.price,
required this.id,
required this.title,
required this.quantity,
required this.price,
});
}

class Cart with ChangeNotifier {
Map<String, CartItem> _items = {};
Map<String?, CartItem> _items = {};

Map<String, CartItem> get items {
Map<String?, CartItem> get items {
return {..._items};
}

Expand All @@ -28,15 +28,15 @@ class Cart with ChangeNotifier {
double get totalAmount {
var total = 0.0;
_items.forEach((key, value) {
total += value.price * value.quantity;
total += value.price! * value.quantity!;
});
return total;
}

void addItem(
String productId,
double price,
String title,
String? productId,
double? price,
String? title,
) {
if (_items.containsKey(productId)) {
_items.update(
Expand All @@ -45,7 +45,7 @@ class Cart with ChangeNotifier {
id: value.id,
title: value.title,
price: value.price,
quantity: value.quantity + 1,
quantity: value.quantity! + 1,
),
);
} else {
Expand All @@ -63,23 +63,23 @@ class Cart with ChangeNotifier {
notifyListeners();
}

void removeItem(String productId) {
void removeItem(String? productId) {
_items.remove(productId);
notifyListeners();
}

void removeSigleItem(String productId) {
void removeSigleItem(String? productId) {
if (!_items.containsKey(productId)) {
return;
}

if (_items[productId].quantity > 1) {
if (_items[productId]!.quantity! > 1) {
_items.update(
productId,
(value) => CartItem(
id: value.id,
title: value.title,
quantity: value.quantity - 1,
quantity: value.quantity! - 1,
price: value.price,
),
);
Expand Down
18 changes: 9 additions & 9 deletions flutter/app/lib/providers/orders.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import './cart.dart';
import 'auth.dart';

class OrderItem {
final String id;
final double amount;
final String? id;
final double? amount;
final List<CartItem> products;
final DateTime dateTime;

OrderItem({
@required this.id,
@required this.amount,
@required this.products,
@required this.dateTime,
required this.id,
required this.amount,
required this.products,
required this.dateTime,
});
}

class Orders with ChangeNotifier {
List<OrderItem> _orders = [];
final String authToken;
final String userId;
final String? authToken;
final String? userId;

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

Expand All @@ -39,7 +39,7 @@ class Orders with ChangeNotifier {
final url = Auth.URL + '/orders/$userId.json?auth=$authToken';
try {
final response = await http.get(Uri.parse(url));
final extractedData = json.decode(response.body) as Map<String, dynamic>;
final extractedData = json.decode(response.body) as Map<String, dynamic>?;
if (extractedData == null) {
return;
}
Expand Down
26 changes: 13 additions & 13 deletions flutter/app/lib/providers/product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import 'package:http/http.dart' as http;
import 'auth.dart';

class Product with ChangeNotifier {
final String id;
final String title;
final String description;
final double price;
final String imageUrl;
bool isFavorite;
final String? id;
final String? title;
final String? description;
final double? price;
final String? imageUrl;
bool? isFavorite;

Product({
@required this.id,
@required this.title,
@required this.description,
@required this.price,
@required this.imageUrl,
required this.id,
required this.title,
required this.description,
required this.price,
required this.imageUrl,
this.isFavorite = false,
});

Expand All @@ -33,9 +33,9 @@ class Product with ChangeNotifier {
};
}

Future<void> toggleFavoriteStatus(String token, String userId) async {
Future<void> toggleFavoriteStatus(String? token, String? userId) async {
final oldStatus = isFavorite;
isFavorite = !isFavorite;
isFavorite = !isFavorite!;
notifyListeners();

if (token != null) {
Expand Down
Loading

0 comments on commit ea255fd

Please sign in to comment.