Could not find a generator for route

flutter clean and run again, is working for me.


Because Of instantiated two MaterialApp widgets. You need to remove the one in MyApp class and may change it to Scaffold

Example:

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
// ...                    
                return new ListTile(
                  onTap: () {                                         
                    Navigator.pushNamed(context, "/listadecompras");
                  },
// ...
}

THE PROBLEM IS YOUR CODE IS - the route is trying to resolve for the nearest MaterialApp which has no route definition. That said you should use only one MaterialApp as the root of your widget tree.


try this :

onPressed: () {
    Navigator.push(
      context,
      new MaterialPageRoute(
        builder: (context) => new ListaDeCompras(),
      ),
    );
  },

If a new file is created and you are defining a route for that new file, its better to re-run the app rather than hot reloading.It worked for me!

Tags:

Flutter