Could not find a generator for route "home-page" in the _MaterialAppState

Viewed 19040

I am getting exception when I trying to navigate from one view to another in flutter app.

I/flutter ( 2199): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 2199): The following assertion was thrown while handling a gesture:
I/flutter ( 2199): Could not find a generator for route "home-page" in the _MaterialAppState.
5 Answers

Use

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

Instead of

Navigator.of(context).pushNamed('/home-page');
//or
Navigator.pushedName(context, '/home-page');

This message tells, that in route list, the route you search aren't listed. So, check if in your MaterialApp->routes have your specified route.

Error says, Could not find a generator for route "home-page" in the _MaterialAppState.. As you are using NamedRoute (inferred from error message) and I think the problem is with route setting. Refer the example for route setting,

 MaterialApp(
    title: 'Named Routes Demo',
    initialRoute: '/',
    routes: { //route setting
      '/': (context) => FirstScreen(),
      '/home-page': (context) => HomePage(), //you should have something like this.
    },
  )

Try it

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

You need to define the route in specific dart file from where you want to jump to next screen. In your case for example there are three screens : 1. mainScreen.dart 2.loginScreen.dart 3.TabScreen.dart

Now you may have defined route for Loginscreen and TabScreen inside mainscreen.dart like :

routes : <String, WidgetBuilder>{
'/login' : (BuildContext context)=> LoginScreen()
'/tab' : (BuildContext context)=> TabScreen()
}

and you are trying to jump from LoginScreen to TabScreen but you haven't defined the route for TabScreen inside LoginScreen.dart

Please make Sure you have defined route for TabScreen inside LoginScreen :

routes : <String, WidgetBuilder>{
'/tab' : (BuildContext context)=> TabScreen()
}
Related