I have the following route in my goRoute:
GoRoute(
path: '/new-proposal-page1',
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: (context, state) => CupertinoPage(
child: NewProposalPage1(trip: state.extra as Trip),
),
),
As you can see this route requires a ‘trip’ object to be passed through.
From this first page, I want to navigate to a second one. I would define the route stack as follows:
GoRoute(
path: '/new-proposal-page1',
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: (context, state) => CupertinoPage(
child: NewProposalPage1(trip: state.extra as Trip),
),
routes: [
GoRoute(
path: 'new-proposal-page2',
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: (context, newProposalState) => CupertinoPage(
child: BlocProvider.value(
value: newProposalState.extra as NewProposalBloc,
child: const NewProposalPage2(),
),
),
),
]
),
In this subroute, I need to pass the Bloc intance that I’ve defined in NewProposalPage1. Unfortunately, when I try to access NewProposalPage2 the system throw this error:
type 'NewProposalBloc' is not a subtype of type 'Trip' in type cast
The issue appears to be that the go Router is not able to handle two different “extra” parameters in the same route stack.
I attempted to move NewProposalPage2 out from the same route stack as NewProposalPage1, and this approach worked.
GoRoute(
path: '/new-proposal-page1',
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: (context, state) => CupertinoPage(
child: NewProposalPage1(trip: state.extra as Trip),
),
),
GoRoute(
path: '/new-proposal-page2',
parentNavigatorKey: _rootNavigatorKey,
pageBuilder: (context, newProposalState) => CupertinoPage(
child: BlocProvider.value(
value: newProposalState.extra as NewProposalBloc,
child: const NewProposalPage2(),
),
),
),
but I still think that this is not the best solution as now the two pages are in two different route stacks.
Do you know how to solve the issue having the two routes in the same route stack? I searched for a solution but I was not able find something.
Thanks to all in advance!
Lewandossi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.