Skip to content

[go_router] Push ShellRoute from inside of other ShellRoute #120791

@vasilich6107

Description

@vasilich6107

Use case

In ShellRoute example we have a /b/details as a route that we are pushing to the root stack.

I tried my best but I failed to create a working solution to push shell route instead of /b/details.
Lets imagine the we are replacing

GoRoute(
  path: 'details',
  parentNavigatorKey: _rootNavigatorKey,
  builder: (BuildContext context, GoRouterState state) {
    return const DetailsScreen(label: 'B');
  },
),

with

ShellRoute(
  builder: (_, __, child) {
    // fancy container with red border for demo purposes
    return Container(child: child);
  },
  routes: [
    GoRoute(
      path: 'details',
      // parentNavigatorKey: _rootNavigatorKey,
      builder: (BuildContext context, GoRouterState state) {
        return const DetailsScreen(label: 'B');
      },
    ),
  ],
)

In this case parentNavigatorKey: _rootNavigatorKey fails with error

Failed assertion: line 431 pos 16: 'route.parentNavigatorKey == null || route.parentNavigatorKey == navigatorKey': is not true.

If i comment out the parentNavigatorKey: _rootNavigatorKey, I'm unable to push this ShellRoute block into _rootNavigatorKey.

Proposal

Please implement the ability to push arbitrary ShellRoute into root stack in the same way as GoRoute can target any stack it would be great to give the same parentNavigatorKey option to ShellRoute

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: go_routerThe go_router packagepackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions