DEV Community

loading...

Flutter : Could not find a generator for route RouteSettings(“/somePage”, null) in the _WidgetsAppState

zeeshanmehdi profile image zeeshan mehdi Updated on ・1 min read

Solution 1 :

Use this:

Navigator.push(context, new MaterialPageRoute(
   builder: (context) => new MyHomePage())
 );

Instead of :

Navigator.of(context)
           .pushReplacementNamed('/somePage');

but in my case it did not fixed.

Let me explain what was problem in my case ,

I had navigation drawer and one of my route was going to a route which had another MaterialApp() Widget and after routing to that page if i route back to any other page it will through this exception. Do you know why ?

because the context was changed to new material app and i was trying to find that route inside new material app but obviously it was not present there.

Before

class App extends StatelessWidget {
  final UserAndManagement userAndManagement;
  App(this.userAndManagement);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        fontFamily: "Varela",
        primaryColor: primaryMaterialColor
      ),
      home: HomePage(userAndManagement),
    );
  }
}

After

class App extends StatelessWidget {
  final UserAndManagement userAndManagement;
  App(this.userAndManagement);
  @override
  Widget build(BuildContext context) {
    return HomePage(userAndManagement);
  }
}

and You guess it worked for me like a charm !!!!

If you were facing the same problem it fixed it give this thumbs up.

Thanks

Discussion (0)

Forem Open with the Forem app