问题描述
我是新手,会在Flutter上发表关于路线和分页器的一个例外.
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 handling a gesture:
Could not find a generator for route "/listadecompras" in the _MaterialAppState.
遵循代码摘录:
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
// ...
return new ListTile(
onTap: () {
Navigator.pushNamed(context, "/listadecompras");
},
// ...
}
class ListaDeCompras extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
// ...
}
}
void main() {
runApp(new MaterialApp(
home: new MyApp(),
routes: <String, WidgetBuilder>{
"/listadecompras": (BuildContext context) => new ListaDeCompras()
}
));
}
请,有人可以给我一些建议吗?预先感谢您的关注
Please, someone could send some advice?thanks in advance for your attention
推荐答案
这是因为您已实例化了两个MaterialApp
小部件.您需要删除MyApp
类中的一个,并可能将其更改为Scaffold
,如下所示:
This is because you have instantiated two MaterialApp
widgets. You need to remove the one in MyApp
class and may change it to Scaffold
instead like this:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
// ...
return new ListTile(
onTap: () {
Navigator.pushNamed(context, "/listadecompras");
},
// ...
}
您的代码中发生的事情是该路由正在尝试解析最接近的MaterialApp
,它没有路由定义.也就是说,应该仅使用一个MaterialApp
作为窗口小部件树的根.
What happened in 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.
这篇关于找不到用于路线的发电机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!