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

20.7k Views Asked by At

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

There are 5 best solutions below

8
On BEST ANSWER

Use

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

Instead of

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

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.
    },
  )
0
On

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()
}
0
On

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.

0
On

Try it

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