Skip to content

[go_router_builder] Add parentNavigatorKey to generated routes. #119294

@lucasbstn

Description

@lucasbstn

Use case

The GoRoute class has a parentNavigatorKey parameter which is useful to specify which Navigator to display the route's screen onto. However when using go_router_builder, there is currently no way of specifying such a key.

Proposal

Implement a way to specify a GlobalKey<NavigatorState?> somewhere when declaring routes to be generated.

Maybe overriding a getter in GoRouteData like so:

final rootNavigatorKey = GlobalKey<NavigatorState>();

@TypedGoRoute<SplashRoute>(
  path: '/splash',
)
class SplashRoute extends GoRouteData {
  const SplashRoute();

  @override
  Widget build(BuildContext context, GoRouterState state) =>
      const SplashScreen();

  @override
  GlobalKey<NavigatorState>? get parentNavigatorKey => rootNavigatorKey;
}

Or specifying the name of the global key like so, which would follow the pattern of how GoRoute are manually declared.

final rootNavigatorKey = GlobalKey<NavigatorState>();

@TypedGoRoute<SplashRoute>(
  path: '/splash',
  parentNavigatorKey:'rootNavigatorKey',
)
class SplashRoute extends GoRouteData {
  const SplashRoute();

  @override
  Widget build(BuildContext context, GoRouterState state) =>
      const SplashScreen();
}

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterp: go_router_builderThe go_router_builder packagepackageflutter/packages repository. See also p: labels.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions