iDecode
iDecode

Reputation: 28986

How to pass parameter to root path (home route) in go_router?

I'm using go_router_builder to build routes. Here's one:

@TypedGoRoute<HomeRoute>(
  path: '/',
)
class HomeRoute extends GoRouteData {
  final Foo? $extra;
  HomeRoute([this.$extra]);

  @override
  Widget build(BuildContext context, GoRouterState state) {
    return HomeScreen();
  }
}

Now the problem is I can't figure out a way to pass the Foo object to HomeRoute in the code.

Upvotes: 2

Views: 724

Answers (1)

burger ham
burger ham

Reputation: 1

You can send your object if you write like below code.

void _tap() => HomeRoute(Foo(id: 1)).go(context);

https://docs.page/csells/go_router/typed-routing#extra-parameter

Upvotes: 0

Related Questions