gpt4 book ai didi

flutter - 命名路由导航错误: type 'MaterialPageRoute' is not a subtype of type 'Route'

转载 作者:IT王子 更新时间:2023-10-29 06:36:23 44 4
gpt4 key购买 nike

我正在尝试使用命名路由导航到另一个页面:

... RaisedButton(
child: Text('Get image'),
onPressed: () => Navigator.pushNamed<String>(
context, '/second'),...

但是报错

> I/flutter (12439): ══╡ EXCEPTION CAUGHT BY GESTURE
> ╞═══════════════════════════════════════════════════════════════════
> I/flutter (12439): The following assertion was thrown while handling a gesture:
> I/flutter (12439): type 'MaterialPageRoute<dynamic>' is not a subtype of type 'Route<String>'
> I/flutter (12439): Either the assertion indicates an error in the framework itself, or we should provide substantially
> I/flutter (12439): more information in this error message to help you determine and fix the underlying cause.
> I/flutter (12439): In either case, please report this assertion by filing a bug on GitHub:
> I/flutter (12439): https://github.com/flutter/flutter/issues/new?template=BUG.md
> I/flutter (12439): When the exception was thrown, this was the stack:
> I/flutter (12439): #0 NavigatorState._routeNamed package:flutter/…/widgets/navigator.dart:1426
> I/flutter (12439): #1 NavigatorState.pushNamed package:flutter/…/widgets/navigator.dart:1473
> I/flutter (12439): #2 Navigator.pushNamed package:flutter/…/widgets/navigator.dart:740
> I/flutter (12439): #3 _CompleterState.build.<anonymous closure> package:my_package/completer.dart:205

路由定义在首页:

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'XXXX',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Completer(),
routes: {
'/second': (BuildContext context) => SecondPage(),
},
onUnknownRoute: (RouteSettings settings) {
return MaterialPageRoute(
builder: (BuildContext context) => Completer(),
);
},
);
}
}

我在此错误消息中找不到任何内容,因此我似乎生成了一个其他人以前从未见过的错误。

我正在慢慢修改代码以将其简化到最低限度,找出我做错了什么,但任何指点将不胜感激。

最佳答案

事后看来显而易见。

我在 Navigator.pushNamed<String>() 中添加了字符串类型提示因为我认为我可以从电话中收到一个键入的值。删除它并将其接收到 var 中解决了这个问题。

将此问题留给其他处于相同状态的人。

关于flutter - 命名路由导航错误: type 'MaterialPageRoute<dynamic>' is not a subtype of type 'Route<String>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54931283/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com