1.到main文件声明路由
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: _navigatorKey,
navigatorObservers: [routeObserver],
routes: {
// 显式声明路由
// "/":(context) => RootPage(),
"Home": (context) => HomePage(),
"Login": (context) => LoginPage(),
"PersonalInfoPage": (context) => PersonalInfoPage(),
"FaultDetectionPage": (context) => FaultDetectionPage(),
"RestartMachinePage": (context) => RestartMachinePage()
},
home: StartPage(),
);
}
2.push的时候也用相应的push方法
Navigator.pushNamed(context, 'FaultDetectionPage',
arguments:{'no': widget.no, 'mac': getMacStr(result), 'code': code});
3.接收参数,参数需要再buildContext里面接收
@override
Widget build(BuildContext context) {
// TODO: implement build
// 路由获取界面传值
Map arguments = ModalRoute.of(context).settings.arguments;
print("argument=====${arguments}");
no = arguments["no"].toString();
mac = arguments["mac"].toString();
code = arguments["code"].toString();
...
}
4.pop回指定页面,使用相应的pop方法
Navigator.popUntil(context, ModalRoute.withName("FaultDetectionPage"));
网友评论