Could not find a generator for route

后端 未结 8 1376
谎友^
谎友^ 2021-01-07 17:03

I´m newbie to flutter and reveice one exception about route and paginator in Flutter.

EXCEPTION CAUGHT BY GESTURE
The following assertion was thrown while ha         


        
相关标签:
8条回答
  • 2021-01-07 17:19

    flutter clean and run again, is working for me.

    0 讨论(0)
  • 2021-01-07 17:20

    I have encountered the same error and solved by just restarting the app

    0 讨论(0)
  • 2021-01-07 17:24

    @aziza is the right answer but in some miscellaneous situation in my case

      class RouteGenerator {
      static Route<dynamic> generateRoute(RouteSettings settings) {
        switch (settings.name) {
          case '/':
            MaterialPageRoute(builder: (_) => MyScaffold());
            break;
          case '/homechart':
             MaterialPageRoute(builder: (_) => analytics());
            break;
        }
      }
    }
    

    I forget to return keyword and IDE not showing any error. showing this kind of error.

    Solution is like this :

    class RouteGenerator {
      static Route<dynamic> generateRoute(RouteSettings settings) {
        switch (settings.name) {
          case '/':
         return   MaterialPageRoute(builder: (_) => MyScaffold());
            break;
          case '/homechart':
           return   MaterialPageRoute(builder: (_) => analytics());
            break;
        }
      }
    }
    
    0 讨论(0)
  • 2021-01-07 17:25

    In my case the error was because i deleted the route from main.dart and forgot the update the change in other files

    0 讨论(0)
  • 2021-01-07 17:33

    You have instantiated two MaterialApp widget. You need to remove the one in MyApp class.

    For push

    Navigator.of(context).pushNamed('/screen1')
    

    For Pop: "popAndPushNamed"

    Navigator.of(context).popAndPushNamed('/screen4');
    

    0 讨论(0)
  • 2021-01-07 17:33

    try this :

    onPressed: () {
        Navigator.push(
          context,
          new MaterialPageRoute(
            builder: (context) => new ListaDeCompras(),
          ),
        );
      },
    
    0 讨论(0)
提交回复
热议问题