Getx: How can I use get parameters or arguments in nested router

Created on 3 Jun 2020  路  4Comments  路  Source: jonataslaw/getx

Describe the bug
I'm trying to implement a nested router with get.
Navigating to each nested router is working now.
How can I get arguments or parameters in the nested route?

return Navigator(
      key: Get.nestedKey(1),
      initialRoute: '/',
      onGenerateRoute: (routeSettings) {
        if (routeSettings.name == '/') {
          return GetRouteBase(
            page: MyMainScreen(),
          );
        }
        if (routeSettings.name == '/nested') {
          return GetRouteBase(
            page: MyNestedScreen(),
          );
        }
      },
    );

Is there any way to pass some parameters with the route name?
like '/nested/:id'

Get.arguments only returns my parents arguments but the nested router's arguments

Flutter Version:
Flutter: 1.17.2

Get Version:
get: ^2.7.1

More info is needed

Most helpful comment

Hi @jonataslaw
Any chance to have an implementation of parameters for nested navigation with dynamic routes please ?

All 4 comments

For nested navigators, dynamic parameters are not supported, because onGenerateRoute does not support this type of feature, and I would have to create another Navigator to replace Flutter's Navigator widget and have this functionality. However with Navigator 2.0 coming, doing so now may be a waste of time.

You can made this:

Navigator(
      key: Get.nestedKey(1),
      initialRoute: '/',
      onGenerateRoute: (routeSettings) {
        if (routeSettings.name == '/') {
          return GetRouteBase(
            page: MyMainScreen(),
          );
        }
        if (routeSettings.name == '/nested') {
          return GetRouteBase(
            page: MyNestedScreen(id: routeSettings.arguments), // Pass arguments to parameter
          );
        }
      },
    )

Well, as it is a question, I am closing this.
If in the future I decide to create a widget to support nested navigation with dynamic routes, I will mark this issue to let you know.

Hi @jonataslaw
Any chance to have an implementation of parameters for nested navigation with dynamic routes please ?

Was this page helpful?
0 / 5 - 0 ratings