getx
getx copied to clipboard
Navigator must be provided with an onGenerateRoute handler
I need to change screen and I've used Get.toNamed('/noticeProblem')
but I get the following error:
FlutterError (Navigator.onGenerateRoute was null, but the route named "/noticeProblem" was referenced.
To use the Navigator API with named routes (pushNamed, pushReplacementNamed, or pushNamedAndRemoveUntil), the Navigator must be provided with an onGenerateRoute handler.
The Navigator was:
NavigatorState#a557a(tickers: tracking 1 ticker))
and this is my main.dart
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
return GetMaterialApp.router(
debugShowCheckedModeBanner: false,
getPages: [
GetPage(
name: '/main',
page: () => MenuScreen(),
middlewares: [AuthMiddlware()]),
GetPage(name: '/intro', page: () => const IntroPages()),
GetPage(name: '/noticeProblem', page: () => const MainNoticeUi()),
],
);
}
Try this
GetMaterialApp.router(
debugShowCheckedModeBanner: false,
routeInformationParser: GetInformationParser(initialRoute: '/home'), // add this line
routerDelegate: GetDelegate(), // add this line
...
)
Try this
GetMaterialApp.router( debugShowCheckedModeBanner: false, routeInformationParser: GetInformationParser(initialRoute: '/home'), // add this line routerDelegate: GetDelegate(), // add this line ... )
Still the same error
What helped me (with getx 4.6.5) was to build the GetMaterialApp widget with auto route:
const App({super.key});
@override
Widget build(BuildContext context) {
return GetMaterialApp.router(
getPages: [your list of pages],
routeInformationParser: GetInformationParser(
initialRoute: '/home',
),
routerDelegate: GetDelegate(
backButtonPopMode: PopMode.History,
preventDuplicateHandlingMode:
PreventDuplicateHandlingMode.ReorderRoutes,
),
);
}
then it is possible to route with rootDelegate like:
Get.rootDelegate.toNamed('/your_route_name');