局部路由用Navigator组件来实现
class TabOne extends StatefulWidget {
TabOneState createState() => TabOneState();
}
class TabOneState extends State<TabOne> {
@override
Widget build(BuildContext context) {
return Navigator(
initialRoute: '/',
onGenerateRoute: (RouteSettings settins) {
WidgetBuilder builder;
switch(settins.name) {
case '/':
builder = (context) => RightSide(); // 局部路由子组件
break;
}
return MaterialPageRoute(builder: builder, settings: settins);
},
);
}
}
// 在RightSide中使用自己的上下文context跳转就是局部跳转
Navigator.push(
context,
MaterialPageRoute(builder: (context) => XXX(), fullscreenDialog: true),
);
// 在RightSide中如果想使用全局跳转, 可以预先将顶层组件的上下文储存在全局变量中, 使用顶层的上下文跳转即为全局跳转
Navigator.push(
global.homeContext,
MaterialPageRoute(builder: (context) => AttendClass()),
);