Reputation: 850
I need to add named routes to my app but inside GetMaterialApp.router
I don't have the option for onGenerateRoute
and now when I try to push a named route I get the following error:
FlutterError (Navigator.onGenerateRoute was null, but the route named "/main/noticeProblem" was referenced.
To use the Navigator API with named routes (pushNamed, pushReplacementNamed, or pushNamedAndRemoveUntil), the Navigator must be provided with an onGenerateRoute handler.
I've searched but didn't find a way to fix this
And this is the code:
@override
Widget build(BuildContext context) {
return GetMaterialApp.router(
debugShowCheckedModeBanner: false,
getPages: [
GetPage(
name: '/main',
page: () => MenuScreen(),
middlewares: [FirstRunMiddleware()],
children: [
GetPage(
name: '/noticeProblem',
transition: Transition.leftToRight,
page: () => MainNoticeUi(),
),
],
),
GetPage(name: '/intro', page: () => const IntroPages()),
GetPage(name: '/settings', page: () => const AppSettings()),
],
);
}
And this is how I try to push the new page on the stack:
return GestureDetector(
onTap: () {
Get.toNamed('/main/noticeProblem');
// Get.to(MainNoticeUi()); works as expected but I need to use named routes
},
...
);
Any ways on how I can generate those routes?
P.S: I need to use GetMaterialPage.router
because this middleware: FirstRunMiddleware()
has to be async
Upvotes: 1
Views: 2739
Reputation: 850
After 4 hours of searching I have found a solution, instead of this Get.toNamed('/main/noticeProblem');
, I have to use Get.rootDelegate.toNamed('/main/noticeProblem');
Upvotes: 3