getx icon indicating copy to clipboard operation
getx copied to clipboard

Nested Navigation using GetNavigator

Open nivisi opened this issue 3 years ago • 7 comments

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.

nivisi avatar May 11 '21 22:05 nivisi

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.

Screenshot 2021-07-11 at 3 29 28 AM

ghost avatar Jul 10 '21 19:07 ghost

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.

mhbdev avatar Apr 28 '22 21:04 mhbdev

Why is the initial route not supported. So weird!

derekpitts28 avatar Sep 09 '22 17:09 derekpitts28

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.

vegidio avatar Mar 10 '23 09:03 vegidio

It is being solved in version ^5.0.0-release-candidate-4. You can use it.

hosseinhadi avatar Aug 30 '23 08:08 hosseinhadi

Ive read a document from Get. Hope be useful

https://github.com/jonataslaw/getx/blob/master/documentation/en_US/route_management.md

mattmusk avatar Feb 01 '24 08:02 mattmusk

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.

roiskhoiron avatar Mar 22 '24 07:03 roiskhoiron