1.注册路由
Map<String, WidgetBuilder> routers = {
"简单的列表": (context) {
return new SimpleListViewPage();
},
"简单的布局": (context) {
return new SimpleLayoutPage();
},
"按钮点击": (context) {
return new SimpleCounterPage(title: "测试");
}
};
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Startup Name Generator',
initialRoute: "/",
theme: ThemeData(primaryColor: Colors.white),
home: new RandomWords(),
routes: routers,
);
}
}
2.路由跳转
arguments
就是传递的参数名
onTap: () {
print("routeLists[index]=" + routeLists[index]);
Navigator.of(context)
.pushNamed(routeLists[index], arguments: "hi");
},
3.接收参数
var args = ModalRoute.of(context)?.settings.arguments;
print(args);
4.反向传值
Navigator.pop(context, "我是返回值");
5.接收反向传递的值
onPressed: () async {
var result = await Navigator.push(context,
MaterialPageRoute(builder: (context) {
return SimpleTipRoutePage(text: "测试");
}));
print("返回值为:$result");
}