Ahmed Fwela

WIP

import 'dart:async';
import 'package:get/get.dart';
class HomeController extends GetxController {}
class HomeController extends GetxController {
final now = DateTime.now().obs;
@override
void onReady() {
super.onReady();
Timer.periodic(
Duration(seconds: 1),
(timer) {
now.value = DateTime.now();
},
);
}
}
... ...
... ... @@ -8,9 +8,17 @@ class DashboardView extends GetView<HomeController> {
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
'DashboardView is working',
style: TextStyle(fontSize: 20),
child: Obx(
() => Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'DashboardView is working',
style: TextStyle(fontSize: 20),
),
Text('Time: ${controller.now.value.toString()}')
],
),
),
),
);
... ...
... ... @@ -30,9 +30,9 @@ class HomeView extends GetView<HomeController> {
pickPages: (currentNavStack) {
// will take any route after home
final res = currentNavStack.pickAfterRoute(Routes.HOME);
print('''RouterOutlet rebuild:
currentStack: $currentNavStack
pickedStack: $res''');
// print('''RouterOutlet rebuild:
// currentStack: $currentNavStack
// pickedStack: $res''');
return res;
},
),
... ...
... ... @@ -18,4 +18,10 @@ class ProductsController extends GetxController {
super.onReady();
loadDemoProductsFromSomeWhere();
}
@override
void onClose() {
Get.printInfo(info: 'Products: onClose');
super.onClose();
}
}
... ...
... ... @@ -22,13 +22,8 @@ class AppPages {
GetPage(
name: _Paths.HOME,
page: () => HomeView(),
//TODO: don't group bindings in one place, and instead make each page use its own binding
bindings: [
HomeBinding(),
//These must use [Get.lazyPut] or [Get.create] because their view is created long after they are declared
ProfileBinding(),
ProductsBinding(),
ProductDetailsBinding(),
],
title: null,
middlewares: [
... ... @@ -39,15 +34,18 @@ class AppPages {
name: _Paths.PROFILE,
page: () => ProfileView(),
title: 'Profile',
binding: ProfileBinding(),
),
GetPage(
name: _Paths.PRODUCTS,
page: () => ProductsView(),
title: 'Products',
binding: ProductsBinding(),
children: [
GetPage(
name: _Paths.PRODUCT_DETAILS,
page: () => ProductDetailsView(),
binding: ProductDetailsBinding(),
),
],
),
... ...
... ... @@ -22,13 +22,15 @@ class RouterOutlet<TDelegate extends RouterDelegate<T>, T extends Object>
TDelegate? delegate,
required List<T> Function(TDelegate routerDelegate) currentNavStack,
required List<T> Function(List<T> currentNavStack) pickPages,
required Widget Function(TDelegate, T? page) pageBuilder,
required Widget Function(BuildContext context, TDelegate, T? page)
pageBuilder,
}) : this.builder(
builder: (context, rDelegate, currentConfig) {
final currentStack = currentNavStack(rDelegate);
final picked = pickPages(currentStack);
if (picked.length == 0) return pageBuilder(rDelegate, null);
return pageBuilder(rDelegate, picked.last);
if (picked.length == 0)
return pageBuilder(context, rDelegate, null);
return pageBuilder(context, rDelegate, picked.last);
},
delegate: delegate,
);
... ... @@ -84,11 +86,21 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, GetPage> {
Widget Function(GetDelegate delegate)? emptyStackPage,
required List<GetPage> Function(List<GetPage> currentNavStack) pickPages,
}) : super(
pageBuilder: (rDelegate, page) =>
(page?.page() ??
emptyStackPage?.call(rDelegate) ??
rDelegate.notFoundRoute?.page()) ??
SizedBox.shrink(),
pageBuilder: (context, rDelegate, page) {
final pageRoute = rDelegate.pageRoutes[page];
if (pageRoute != null) {
return pageRoute.buildPage(
context,
pageRoute.animation,
pageRoute.secondaryAnimation,
);
}
/// improve this logic abit
return (emptyStackPage?.call(rDelegate) ??
rDelegate.notFoundRoute?.page()) ??
SizedBox.shrink();
},
currentNavStack: (routerDelegate) => routerDelegate.routes,
pickPages: pickPages,
delegate: Get.getDelegate(),
... ... @@ -99,11 +111,11 @@ class RouterOutletContainerMiddleWare extends GetMiddleware {
final String stayAt;
RouterOutletContainerMiddleWare(this.stayAt);
@override
RouteSettings? redirect(String? route) {
print('RouterOutletContainerMiddleWare: Redirect called ($route)');
return null;
}
// @override
// RouteSettings? redirect(String? route) {
// print('RouterOutletContainerMiddleWare: Redirect called ($route)');
// return null;
// }
}
extension PagesListExt on List<GetPage> {
... ...
... ... @@ -108,9 +108,9 @@ class GetPageRoute<T> extends PageRoute<T> {
@override
Widget buildPage(
BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
BuildContext? context,
Animation<double>? animation,
Animation<double>? secondaryAnimation,
) {
// Get.reference = settings.name ?? routeName;
Get.reference = reference;
... ...