forked from toastguyz/flutter-ecommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
78 lines (75 loc) · 3.17 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import 'package:flutter/material.dart';
import 'package:flutter_ecommerce/helpers/custom_route.dart';
import 'package:flutter_ecommerce/providers/auth.dart';
import 'package:flutter_ecommerce/providers/cart.dart';
import 'package:flutter_ecommerce/providers/orders.dart';
import 'package:flutter_ecommerce/providers/products.dart';
import 'package:flutter_ecommerce/screens/auth_screen.dart';
import 'package:flutter_ecommerce/screens/cart_screen.dart';
import 'package:flutter_ecommerce/screens/edit_product_screen.dart';
import 'package:flutter_ecommerce/screens/orders_screen.dart';
import 'package:flutter_ecommerce/screens/splash_screen.dart';
import 'package:flutter_ecommerce/screens/user_products_screen.dart';
import 'package:provider/provider.dart';
import './screens/products_overview_screen.dart';
import './screens/product_detail_screen.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// return ChangeNotifierProvider(
// builder: (BuildContext context) => Products(),
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: Auth(),
),
ChangeNotifierProxyProvider<Auth, Products>(
builder: (context, auth, previousProducts) => Products(
auth.token,
auth.userId,
previousProducts == null ? [] : previousProducts.items),
),
ChangeNotifierProxyProvider<Auth, Orders>(
builder: (context, auth, previousOrders) => Orders(auth.token,
auth.userId, previousOrders == null ? [] : previousOrders.orders),
),
ChangeNotifierProvider.value(
value: Cart(),
),
],
child: Consumer<Auth>(
builder: (BuildContext context, Auth auth, Widget child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'E-Store',
theme: ThemeData(
primarySwatch: Colors.green,
accentColor: Colors.redAccent,
fontFamily: 'Lato',
pageTransitionsTheme: PageTransitionsTheme(builders: {
TargetPlatform.android: CustomPageTransitionsBuilder(),
TargetPlatform.iOS: CustomPageTransitionsBuilder(),
}),
),
home: auth.isAuth
? ProductsOverviewScreen()
: FutureBuilder(
future: auth.tryAutoLogin(),
builder: (BuildContext context, AsyncSnapshot snapshot) =>
snapshot.connectionState == ConnectionState.waiting
? SplashScreen()
: AuthScreen(),
),
routes: {
ProductDetailScreen.routeName: (ctx) => ProductDetailScreen(),
CartScreen.routeName: (ctx) => CartScreen(),
OrdersScreen.routeName: (ctx) => OrdersScreen(),
UserProductsScreen.routeName: (ctx) => UserProductsScreen(),
EditProductScreen.routeName: (ctx) => EditProductScreen(),
});
},
),
);
}
}