编写Flutter的推动参数转移时发生了错误,但是在查询大量信息后仍未解决问题
我正在构建一个简单的Flutter应用程序,并且使用命名路由来传递参数遇到困难。 我收到了错误消息,
Receiver: Closure: (dynamic) => Home
Tried calling: new MyApp.<anonymous closure>(Instance of 'StatelessElement', arguments: _LinkedHashMap len:4)
Found: new MyApp.<anonymous closure>(dynamic) => Home
我的主接口代码是
import 'package:world_time/pages/Library.dart';
import 'package:world_time/pages/home.dart';
import 'package:world_time/pages/choose_location.dart';
import 'package:world_time/pages/loading.dart';
import 'package:world_time/pages/details.dart';
import 'package:world_time/pages/setting.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget{
MyApp({Key? key}) : super(key: key);
final routes = {
'/': (context) => Loading(),
'/home': (context) => Home(),
'/setting': (context) => ChangeSetting(),
'/library': (context) => ChooseLibrary(),
'/location': (context) => ChooseLocation(),
'/details': (context,{arguments}) => Details(arguments:arguments),
};
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Loading(),
onGenerateRoute: (RouteSettings settings) {
final String? name = settings.name;
final Function pageContentBuilder = this.routes[name] as Function;
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute(
builder: (context) => pageContentBuilder(context, arguments: settings.arguments));
return route;
} else {
final Route route = MaterialPageRoute(
builder: (context) => pageContentBuilder(context));
return route;
}
}
}
);
}
}
从加载到家庭的自动加载,家庭可以导航设置,库和位置。设置,库和位置都可以浏览详细信息。 我希望通过ongererateroute将参数传递,以便我可以轻松完成以下页面中的相应数据处理。但是我现在无法运行整个项目。 我查找了很多,我无法弄清楚正确的代码。这是我第一次写一个扑朔迷离的项目,我希望得到帮助。
I'm building a simple flutter app and I'm having trouble passing parameters using named routes.
I got the error message
Receiver: Closure: (dynamic) => Home
Tried calling: new MyApp.<anonymous closure>(Instance of 'StatelessElement', arguments: _LinkedHashMap len:4)
Found: new MyApp.<anonymous closure>(dynamic) => Home
My main interface code is
import 'package:world_time/pages/Library.dart';
import 'package:world_time/pages/home.dart';
import 'package:world_time/pages/choose_location.dart';
import 'package:world_time/pages/loading.dart';
import 'package:world_time/pages/details.dart';
import 'package:world_time/pages/setting.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget{
MyApp({Key? key}) : super(key: key);
final routes = {
'/': (context) => Loading(),
'/home': (context) => Home(),
'/setting': (context) => ChangeSetting(),
'/library': (context) => ChooseLibrary(),
'/location': (context) => ChooseLocation(),
'/details': (context,{arguments}) => Details(arguments:arguments),
};
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Loading(),
onGenerateRoute: (RouteSettings settings) {
final String? name = settings.name;
final Function pageContentBuilder = this.routes[name] as Function;
if (pageContentBuilder != null) {
if (settings.arguments != null) {
final Route route = MaterialPageRoute(
builder: (context) => pageContentBuilder(context, arguments: settings.arguments));
return route;
} else {
final Route route = MaterialPageRoute(
builder: (context) => pageContentBuilder(context));
return route;
}
}
}
);
}
}
Automatically load from loading to home, home can navigate setting, library and location. Setting, library and location can all navigate details.
I hope to pass parameters through onGenerateRoute, so that I can easily complete the corresponding data processing in the following pages. But I can't run the whole project now.
I've looked up a lot and I can't figure out the correct code. This is my first time writing a flutter project and I hope to get help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论