getx
getx copied to clipboard
Nested Navigation using GetNavigator
Describe the bug
Unable to use the GetNavigator
for nested navigation.
Reproduction code
I've made a tiny repro project. It is placed in this repo.
The snippet of GetNavigator
usage:
class HomePage extends GetView<HomeController> {
final pages = [
Navigator(
key: Get.nestedKey(AppRoutes.todosKey),
initialRoute: AppRoutes.todos,
onGenerateRoute: (settings) {
return GetPageRoute(
settings: settings,
page: () {
if (settings.name == '/') {
return Text('Initial');
}
if (settings.name == AppRoutes.todos) {
return TodosPage();
}
final id = settings.name.replaceFirst(AppRoutes.todos + '/', '');
Get.put(TodoController(id));
return TodoPage();
},
);
},
),
GetNavigator(
key: Get.nestedKey(AppRoutes.notesKey),
initialRoute: AppRoutes.notes,
getPages: [
GetPage(
name: AppRoutes.notes,
page: () {
return NotesPage();
},
),
GetPage(
name: '${AppRoutes.notes}/:id',
binding: NoteBinding(),
page: () {
return NotePage();
},
),
],
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GetNavigator Issue'),
actions: [
IconButton(
onPressed: () {
Get.toNamed('${AppRoutes.test}/ThisIsTheTest');
},
icon: Text('Test'),
)
],
),
bottomNavigationBar: GetBuilder(
init: controller,
builder: (controller) => BottomNavigationBar(
currentIndex: controller.index,
onTap: controller.changeIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.today),
label: 'Todos',
),
BottomNavigationBarItem(
icon: Icon(Icons.note),
label: 'Notes',
),
],
),
),
body: GetBuilder(
init: controller,
builder: (controller) => IndexedStack(
children: pages,
index: controller.index,
),
),
);
}
}
And this is the output I see in the console:
=[GETX] Route "/notes" not found
════════ Exception caught by widgets library ═══════════════════════════════════
Null check operator used on a null value
The relevant error-causing widget was
GetNavigator-[LabeledGlobalKey<NavigatorState>#13608]
lib/pages/home_page.dart:36
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Multiple widgets used the same GlobalKey.
The key [LabeledGlobalKey<NavigatorState>#13608] was used by 2 widgets
GetNavigator-[LabeledGlobalKey<NavigatorState>#13608]
Navigator-[LabeledGlobalKey<NavigatorState>#13608]
dirty
dependencies: [UnmanagedRestorationScope, _EffectiveTickerMode]
state: NavigatorState#6bd96(lifecycle state: initialized)
════════════════════════════════════════════════════════════════════════════════
Expected behavior
GetNavigator
is available to use for nested navigation.
Flutter Version: 2.0.6
Getx Version: 4.1.4
Hey! Thanks for an awesome package.
Nested navigation is a required feature in my project. I've seen examples using the standard Flutter Navigator, and they work. But the GetNavigator
is way more powerful than the default navigator. It would be nice to use it for named navigation.
May I know why unable to use GetRouterOutlet only after imported the Getx package? Pubspec already declare version 4.1.4 and other feature is working fine.
GetNavigator class on the latest release does not even support initialRoute property! why is that. and this navigator class is so weak and ofc not working anyway.
Why is the initial route not supported. So weird!
I found this issue 2 years after it was first created but it seems there's not a solution for it yet?
initialRoute
is such a fundamental thing to make a navigator works and it's weird it's no longer present. Regardless, the lack of documentation in the lib makes everything much worse.
It is being solved in version ^5.0.0-release-candidate-4
. You can use it.
Ive read a document from Get. Hope be useful
https://github.com/jonataslaw/getx/blob/master/documentation/en_US/route_management.md
Ive read a document from Get. Hope be useful
https://github.com/jonataslaw/getx/blob/master/documentation/en_US/route_management.md
i have been tried and its work. but when we use Get.to() with arguments its still null value of Get.argument result.