DEV Community

zeeshan mehdi
zeeshan mehdi

Posted on • Updated on

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

Solution 1 :

Use this:

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

Enter fullscreen mode Exit fullscreen mode

Instead of :

Navigator.of(context)
           .pushReplacementNamed('/somePage');
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

After

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

Enter fullscreen mode Exit fullscreen mode

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

Top comments (1)

Collapse
 
cmrbslgj profile image
cmrbslgj

this very good but I dont back previous page :(