Showing
7 changed files
with
66 additions
and
28 deletions
1 | +import 'dart:async'; | ||
2 | + | ||
1 | import 'package:get/get.dart'; | 3 | import 'package:get/get.dart'; |
2 | 4 | ||
3 | -class HomeController extends GetxController {} | 5 | +class HomeController extends GetxController { |
6 | + final now = DateTime.now().obs; | ||
7 | + @override | ||
8 | + void onReady() { | ||
9 | + super.onReady(); | ||
10 | + Timer.periodic( | ||
11 | + Duration(seconds: 1), | ||
12 | + (timer) { | ||
13 | + now.value = DateTime.now(); | ||
14 | + }, | ||
15 | + ); | ||
16 | + } | ||
17 | +} |
@@ -8,9 +8,17 @@ class DashboardView extends GetView<HomeController> { | @@ -8,9 +8,17 @@ class DashboardView extends GetView<HomeController> { | ||
8 | Widget build(BuildContext context) { | 8 | Widget build(BuildContext context) { |
9 | return Scaffold( | 9 | return Scaffold( |
10 | body: Center( | 10 | body: Center( |
11 | - child: Text( | ||
12 | - 'DashboardView is working', | ||
13 | - style: TextStyle(fontSize: 20), | 11 | + child: Obx( |
12 | + () => Column( | ||
13 | + mainAxisSize: MainAxisSize.min, | ||
14 | + children: [ | ||
15 | + Text( | ||
16 | + 'DashboardView is working', | ||
17 | + style: TextStyle(fontSize: 20), | ||
18 | + ), | ||
19 | + Text('Time: ${controller.now.value.toString()}') | ||
20 | + ], | ||
21 | + ), | ||
14 | ), | 22 | ), |
15 | ), | 23 | ), |
16 | ); | 24 | ); |
@@ -30,9 +30,9 @@ class HomeView extends GetView<HomeController> { | @@ -30,9 +30,9 @@ class HomeView extends GetView<HomeController> { | ||
30 | pickPages: (currentNavStack) { | 30 | pickPages: (currentNavStack) { |
31 | // will take any route after home | 31 | // will take any route after home |
32 | final res = currentNavStack.pickAfterRoute(Routes.HOME); | 32 | final res = currentNavStack.pickAfterRoute(Routes.HOME); |
33 | - print('''RouterOutlet rebuild: | ||
34 | - currentStack: $currentNavStack | ||
35 | - pickedStack: $res'''); | 33 | + // print('''RouterOutlet rebuild: |
34 | + // currentStack: $currentNavStack | ||
35 | + // pickedStack: $res'''); | ||
36 | return res; | 36 | return res; |
37 | }, | 37 | }, |
38 | ), | 38 | ), |
@@ -18,4 +18,10 @@ class ProductsController extends GetxController { | @@ -18,4 +18,10 @@ class ProductsController extends GetxController { | ||
18 | super.onReady(); | 18 | super.onReady(); |
19 | loadDemoProductsFromSomeWhere(); | 19 | loadDemoProductsFromSomeWhere(); |
20 | } | 20 | } |
21 | + | ||
22 | + @override | ||
23 | + void onClose() { | ||
24 | + Get.printInfo(info: 'Products: onClose'); | ||
25 | + super.onClose(); | ||
26 | + } | ||
21 | } | 27 | } |
@@ -22,13 +22,8 @@ class AppPages { | @@ -22,13 +22,8 @@ class AppPages { | ||
22 | GetPage( | 22 | GetPage( |
23 | name: _Paths.HOME, | 23 | name: _Paths.HOME, |
24 | page: () => HomeView(), | 24 | page: () => HomeView(), |
25 | - //TODO: don't group bindings in one place, and instead make each page use its own binding | ||
26 | bindings: [ | 25 | bindings: [ |
27 | HomeBinding(), | 26 | HomeBinding(), |
28 | - //These must use [Get.lazyPut] or [Get.create] because their view is created long after they are declared | ||
29 | - ProfileBinding(), | ||
30 | - ProductsBinding(), | ||
31 | - ProductDetailsBinding(), | ||
32 | ], | 27 | ], |
33 | title: null, | 28 | title: null, |
34 | middlewares: [ | 29 | middlewares: [ |
@@ -39,15 +34,18 @@ class AppPages { | @@ -39,15 +34,18 @@ class AppPages { | ||
39 | name: _Paths.PROFILE, | 34 | name: _Paths.PROFILE, |
40 | page: () => ProfileView(), | 35 | page: () => ProfileView(), |
41 | title: 'Profile', | 36 | title: 'Profile', |
37 | + binding: ProfileBinding(), | ||
42 | ), | 38 | ), |
43 | GetPage( | 39 | GetPage( |
44 | name: _Paths.PRODUCTS, | 40 | name: _Paths.PRODUCTS, |
45 | page: () => ProductsView(), | 41 | page: () => ProductsView(), |
46 | title: 'Products', | 42 | title: 'Products', |
43 | + binding: ProductsBinding(), | ||
47 | children: [ | 44 | children: [ |
48 | GetPage( | 45 | GetPage( |
49 | name: _Paths.PRODUCT_DETAILS, | 46 | name: _Paths.PRODUCT_DETAILS, |
50 | page: () => ProductDetailsView(), | 47 | page: () => ProductDetailsView(), |
48 | + binding: ProductDetailsBinding(), | ||
51 | ), | 49 | ), |
52 | ], | 50 | ], |
53 | ), | 51 | ), |
@@ -22,13 +22,15 @@ class RouterOutlet<TDelegate extends RouterDelegate<T>, T extends Object> | @@ -22,13 +22,15 @@ class RouterOutlet<TDelegate extends RouterDelegate<T>, T extends Object> | ||
22 | TDelegate? delegate, | 22 | TDelegate? delegate, |
23 | required List<T> Function(TDelegate routerDelegate) currentNavStack, | 23 | required List<T> Function(TDelegate routerDelegate) currentNavStack, |
24 | required List<T> Function(List<T> currentNavStack) pickPages, | 24 | required List<T> Function(List<T> currentNavStack) pickPages, |
25 | - required Widget Function(TDelegate, T? page) pageBuilder, | 25 | + required Widget Function(BuildContext context, TDelegate, T? page) |
26 | + pageBuilder, | ||
26 | }) : this.builder( | 27 | }) : this.builder( |
27 | builder: (context, rDelegate, currentConfig) { | 28 | builder: (context, rDelegate, currentConfig) { |
28 | final currentStack = currentNavStack(rDelegate); | 29 | final currentStack = currentNavStack(rDelegate); |
29 | final picked = pickPages(currentStack); | 30 | final picked = pickPages(currentStack); |
30 | - if (picked.length == 0) return pageBuilder(rDelegate, null); | ||
31 | - return pageBuilder(rDelegate, picked.last); | 31 | + if (picked.length == 0) |
32 | + return pageBuilder(context, rDelegate, null); | ||
33 | + return pageBuilder(context, rDelegate, picked.last); | ||
32 | }, | 34 | }, |
33 | delegate: delegate, | 35 | delegate: delegate, |
34 | ); | 36 | ); |
@@ -84,11 +86,21 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetPage> { | @@ -84,11 +86,21 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetPage> { | ||
84 | Widget Function(GetDelegate delegate)? emptyStackPage, | 86 | Widget Function(GetDelegate delegate)? emptyStackPage, |
85 | required List<GetPage> Function(List<GetPage> currentNavStack) pickPages, | 87 | required List<GetPage> Function(List<GetPage> currentNavStack) pickPages, |
86 | }) : super( | 88 | }) : super( |
87 | - pageBuilder: (rDelegate, page) => | ||
88 | - (page?.page() ?? | ||
89 | - emptyStackPage?.call(rDelegate) ?? | ||
90 | - rDelegate.notFoundRoute?.page()) ?? | ||
91 | - SizedBox.shrink(), | 89 | + pageBuilder: (context, rDelegate, page) { |
90 | + final pageRoute = rDelegate.pageRoutes[page]; | ||
91 | + if (pageRoute != null) { | ||
92 | + return pageRoute.buildPage( | ||
93 | + context, | ||
94 | + pageRoute.animation, | ||
95 | + pageRoute.secondaryAnimation, | ||
96 | + ); | ||
97 | + } | ||
98 | + | ||
99 | + /// improve this logic abit | ||
100 | + return (emptyStackPage?.call(rDelegate) ?? | ||
101 | + rDelegate.notFoundRoute?.page()) ?? | ||
102 | + SizedBox.shrink(); | ||
103 | + }, | ||
92 | currentNavStack: (routerDelegate) => routerDelegate.routes, | 104 | currentNavStack: (routerDelegate) => routerDelegate.routes, |
93 | pickPages: pickPages, | 105 | pickPages: pickPages, |
94 | delegate: Get.getDelegate(), | 106 | delegate: Get.getDelegate(), |
@@ -99,11 +111,11 @@ class RouterOutletContainerMiddleWare extends GetMiddleware { | @@ -99,11 +111,11 @@ class RouterOutletContainerMiddleWare extends GetMiddleware { | ||
99 | final String stayAt; | 111 | final String stayAt; |
100 | 112 | ||
101 | RouterOutletContainerMiddleWare(this.stayAt); | 113 | RouterOutletContainerMiddleWare(this.stayAt); |
102 | - @override | ||
103 | - RouteSettings? redirect(String? route) { | ||
104 | - print('RouterOutletContainerMiddleWare: Redirect called ($route)'); | ||
105 | - return null; | ||
106 | - } | 114 | + // @override |
115 | + // RouteSettings? redirect(String? route) { | ||
116 | + // print('RouterOutletContainerMiddleWare: Redirect called ($route)'); | ||
117 | + // return null; | ||
118 | + // } | ||
107 | } | 119 | } |
108 | 120 | ||
109 | extension PagesListExt on List<GetPage> { | 121 | extension PagesListExt on List<GetPage> { |
@@ -108,9 +108,9 @@ class GetPageRoute<T> extends PageRoute<T> { | @@ -108,9 +108,9 @@ class GetPageRoute<T> extends PageRoute<T> { | ||
108 | 108 | ||
109 | @override | 109 | @override |
110 | Widget buildPage( | 110 | Widget buildPage( |
111 | - BuildContext context, | ||
112 | - Animation<double> animation, | ||
113 | - Animation<double> secondaryAnimation, | 111 | + BuildContext? context, |
112 | + Animation<double>? animation, | ||
113 | + Animation<double>? secondaryAnimation, | ||
114 | ) { | 114 | ) { |
115 | // Get.reference = settings.name ?? routeName; | 115 | // Get.reference = settings.name ?? routeName; |
116 | Get.reference = reference; | 116 | Get.reference = reference; |
-
Please register or login to post a comment