Jonny Borges

add InheritedNavigator

... ... @@ -8,7 +8,7 @@ FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386
EXCLUDED_ARCHS[sdk=iphoneos*]=armv7
DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9iMjAxODNlMDQwOTYwOTRiY2MzN2Q5Y2RlMmE0Yjk2ZjVjYzY4NGNmLw==
DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9iOGQzNTgxMGU5MWFiOGZjMzliYTVlN2E0MWJmZjZmNjk3ZThlM2E4Lw==
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=true
TREE_SHAKE_ICONS=false
... ...
... ... @@ -7,7 +7,7 @@ export "FLUTTER_TARGET=/Users/jonatasborges/getx5/getx/example_nav2/lib/main.dar
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9iMjAxODNlMDQwOTYwOTRiY2MzN2Q5Y2RlMmE0Yjk2ZjVjYzY4NGNmLw=="
export "DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC9iOGQzNTgxMGU5MWFiOGZjMzliYTVlN2E0MWJmZjZmNjk3ZThlM2E4Lw=="
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
... ...
... ... @@ -63,4 +63,3 @@ class HomeView extends GetView<HomeController> {
);
}
}
... ...
... ... @@ -37,7 +37,6 @@ class ProfileView extends GetView<ProfileController> {
child: const Text('Show a test dialog in Home router outlet'),
onPressed: () {
//shows a dialog
Get.defaultDialog(
title: 'Test Dialog In Home Outlet !!',
barrierDismissible: true,
... ...
... ... @@ -75,6 +75,10 @@ class RouteDecoder {
@override
int get hashCode => currentTreeBranch.hashCode ^ pageSettings.hashCode;
@override
String toString() =>
'RouteDecoder(currentTreeBranch: $currentTreeBranch, pageSettings: $pageSettings)';
}
class ParseRouteTree {
... ...
... ... @@ -127,18 +127,22 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> {
].whereType<GetPage>();
if (pageRes.isNotEmpty) {
return GetNavigator(
restorationScopeId: restorationScopeId,
onPopPage: onPopPage ??
(route, result) {
final didPop = route.didPop(result);
if (!didPop) {
return false;
}
return true;
},
pages: pageRes.toList(),
key: navigatorKey,
return InheritedNavigator(
navigatorKey: navigatorKey ??
Get.rootController.rootDelegate.navigatorKey,
child: GetNavigator(
restorationScopeId: restorationScopeId,
onPopPage: onPopPage ??
(route, result) {
final didPop = route.didPop(result);
if (!didPop) {
return false;
}
return true;
},
pages: pageRes.toList(),
key: navigatorKey,
),
);
}
return (emptyWidget?.call(rDelegate) ?? const SizedBox.shrink());
... ... @@ -163,6 +167,30 @@ class GetRouterOutlet extends RouterOutlet<GetDelegate, RouteDecoder> {
);
}
class InheritedNavigator extends InheritedWidget {
const InheritedNavigator({
super.key,
required super.child,
required this.navigatorKey,
});
final GlobalKey<NavigatorState> navigatorKey;
static InheritedNavigator? of(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<InheritedNavigator>();
}
@override
bool updateShouldNotify(InheritedNavigator oldWidget) {
return true;
}
}
extension NavKeyExt on BuildContext {
GlobalKey<NavigatorState>? get parentNavigatorKey {
return InheritedNavigator.of(this)?.navigatorKey;
}
}
extension PagesListExt on List<GetPage> {
/// Returns the route and all following routes after the given route.
Iterable<GetPage> pickFromRoute(String route) {
... ... @@ -225,7 +253,8 @@ mixin RouterListenerMixin<T extends StatefulWidget> on State<T> {
super.didChangeDependencies();
disposer?.call();
final router = Router.of(context);
delegate ??= router.routerDelegate;
delegate ??= router.routerDelegate as GetDelegate;
delegate?.addListener(_listener);
disposer = () => delegate?.removeListener(_listener);
}
... ...