定义命名路由
//引入两个页面组件
import 'pages/homePage/seach.dart';
import 'pages/homePage/edit.dart';
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Tabs(),
//定义命名路由
routes: {
'/seach': (context)=>Seach(),
'/edit': (context)=>Edit(),
},
);
}
}
传值
Navigator.of(context).pushNamed('/edit',arguments: "我是传给编辑页面的");
接收
使用:ModalRoute.of(context).settings.arguments
class _EditState extends State<Edit> {
String title;
@override
Widget build(BuildContext context) {
setState(() {
this.title = ModalRoute.of(context).settings.arguments;
});
return Scaffold(
appBar: AppBar(title: Text(this.title)),
body: Text("设置内容"),
);
}
}
网友评论