一、配置路由
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter",
routes: {
"detail":(context)=>MyDetail(),
"home":(context)=>HomeContent()
},
home: Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: HomeContent(),
),
);
}
}
二、跳转
class _HomeContnetState extends State {
@override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
RaisedButton(child: Text("detail"),onPressed: goDetail,),
],
);
}
void goDetail(){
Navigator.pushNamed(context, "detail");
}
}
三、跳转传参
Home页
//home.dart
void getDetail(){
Navigator.of(context).pushNamed("detail",arguments: "10011");
}
详情页
class MyDetail extends StatelessWidget {
@override
Widget build(BuildContext context) {
var args = ModalRoute.of(context).settings.arguments;
print(args);
return Scaffold(
appBar: AppBar(
title: Text('Title'),
),
body: Container(
child: Text("详情页"),
),
);
}
}