Reputation: 7216
I want to convert the old solution based on Navigator api on go_router, but have problems with the following logic.
old Navigator solution (it works):
Widget buildListItem(BuildContext context, RapportData rapportData) {
return GestureDetector(
onTap: () {
onTapFunction(context, Group(rapportData));
},
child: ...
}
onTapFunction(BuildContext context, Widget route) async {
final bool? result = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => route,
),
);
debugPrint('-/////////////// $result');
}
while new go_router variant looks like this (error):
onTapFunctionGo(context, rapportData);
onTapFunctionGo(BuildContext context, RapportData rData) {
final bool result = context.go('groupWithExtraParam', extra: rData) as bool; // error line
debugPrint('-/////////////// $result');
}
and the corresponding go route:
GoRoute(
path: 'rapports',
builder: (context, state) {
return const RapportListViewMod();
},
routes: [
GoRoute( // this one
path: 'groupWithExtraParam',
builder: (context, state) {
final rData = state.extra! as RapportData;
return Group(rData);
},
)
],
),
the error is in the line with the comment 'error line':
type 'Null' is not a subtype of type 'bool' in type cast
Here I tried to replicate the logic of the old solution, but can't go_router return the result?
update: so far I changed context.go to context.push and changed the routs structure and after that it works. But now there is another question. It now works with the following routes config (where groupWithExtraParam is no more a child rote in 'rapports'):
final _router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) => const HomeView(),
routes: [
GoRoute(
path: 'rapports',
builder: (context, state) {
return const RapportListViewMod();
},
)
],
),
GoRoute(
path: '/groupWithExtraParam',
builder: (context, state) {
final rData = state.extra! as RapportData;
return Group(rData);
},
),
],
);
But what was wrong with the initial router confing where the 'groupWithExtraParam' was a child in 'rapports' route?
Can't the routes configuration contain nested ‘routes’ sections?
Upvotes: 0
Views: 43