getx icon indicating copy to clipboard operation
getx copied to clipboard

Navigator must be provided with an onGenerateRoute handler

Open SK1n opened this issue 2 years ago • 3 comments

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()),
      ],
    );
  }

SK1n avatar Jul 09 '22 18:07 SK1n

Try this

GetMaterialApp.router(
      debugShowCheckedModeBanner: false,
      routeInformationParser: GetInformationParser(initialRoute: '/home'),  // add this line
      routerDelegate: GetDelegate(),  // add this line
      ...
)

Remering avatar Jul 12 '22 09:07 Remering

Try this

GetMaterialApp.router(
      debugShowCheckedModeBanner: false,
      routeInformationParser: GetInformationParser(initialRoute: '/home'),  // add this line
      routerDelegate: GetDelegate(),  // add this line
      ...
)

Still the same error

SK1n avatar Jul 26 '22 00:07 SK1n

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');

wpfilf avatar Aug 03 '22 19:08 wpfilf