我是 Flutter 中关于路由和分页器的一个异常(exception)的新手。
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()
}
));
}
拜托,有人可以提供一些建议吗? 提前感谢您的关注
最佳答案
因为实例化了两个 MaterialApp
小部件。您需要删除 MyApp
类中的那个,并可以将其更改为 Scaffold
例子:
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
// ...
return new ListTile(
onTap: () {
Navigator.pushNamed(context, "/listadecompras");
},
// ...
}
问题是您的代码是 - 路线试图解析最近的没有路线定义的 MaterialApp
。也就是说,您应该只使用一个 MaterialApp
作为小部件树的根。
https://stackoverflow.com/questions/49132299/
相关文章:
http - 在flutter http请求中为所有请求设置默认 header 的最佳方法
android - 使用 google dart 语言的原生移动应用程序
dart - Flutter - 无法构建,因为框架已经在构建
dart - 输入文本时自动扩展的 Flutter 文本字段,然后在达到特定高度时开始滚动文本
android - 如何在 Flutter 中创建可扩展的 ListView
dart - Flutter 测试 MissingPluginException
api - 为 HTTPClient get() 请求设置超时