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

5

5

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.
Fuse answered 19/9, 2018 at 12:7 Comment(1)
Code Hunter, you need to share your code. I think I know the answer but I need to confirm how you are using Navigator.pushAllgood
A
30

Use

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

Instead of

Navigator.of(context).pushNamed('/home-page');
//or
Navigator.pushedName(context, '/home-page');
Allgood answered 19/9, 2018 at 13:10 Comment(8)
This was a solution for me; however push doesn't seem to support an object as an argument? any idea to circumvent that limitation?Inundate
@Inundate did you figure it out? Did you mean you wanted to pass an object through the MyHomePage() method e.g new MyHomePage(fooObj) so that it could be used there?Allgood
not at my computer right now but I remember creating a class to hold the parameters, so it was something like this: class PageParameters { final num id; final String title; PageParameters(this.id,this.title); }Inundate
class RequestEditPage extends StatelessWidget { final PageParameters data; RequestEditPage({this.data}); Inundate
Sorry the bad formatting, but yes, basically you add this object in the page widget and you send the data as a parameter to the new page in the push operation. I got my inspiration here linkInundate
Since your class has those parameters in your build method you should be able to reference your object using widget.object eg. widget.data, widget.title etc.Allgood
Any explanation to why?Oast
Add an explanations for this... why?Overlord
E
2

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.

Emelia answered 28/5, 2019 at 10:51 Comment(0)
D
0

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.
    },
  )
Danieu answered 19/9, 2018 at 14:31 Comment(0)
M
0

Try it

  Navigator.push(context, new MaterialPageRoute(builder: (context) =>new PageName())
Minnow answered 20/5, 2019 at 16:41 Comment(0)
P
0

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()
}
Petroleum answered 30/6, 2019 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.