1、通过of跳转
//在入口定义路由
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo', //应用名
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Hello Flutter'),
//定义路由
routes: <String,WidgetBuilder>{
"/basicComponent":(BuildContext context)=>const BasicComponent(), //通过of跳转使用定义的路由名
},
);
}
}
//路由跳转
Navigator.of(context).pushNamed("/basicComponent");
2、通过push跳转
Navigator.push(context, MaterialPageRoute(builder: (context)=>const BasicComponent()));
//或
Navigator.push(context,MaterialPageRoute(builder: (context) {
return const BasicComponent();
}));
3、传递参数
|