局部路由用Navigator组件来实现

    1. class TabOne extends StatefulWidget {
    2. TabOneState createState() => TabOneState();
    3. }
    4. class TabOneState extends State<TabOne> {
    5. @override
    6. Widget build(BuildContext context) {
    7. return Navigator(
    8. initialRoute: '/',
    9. onGenerateRoute: (RouteSettings settins) {
    10. WidgetBuilder builder;
    11. switch(settins.name) {
    12. case '/':
    13. builder = (context) => RightSide(); // 局部路由子组件
    14. break;
    15. }
    16. return MaterialPageRoute(builder: builder, settings: settins);
    17. },
    18. );
    19. }
    20. }
    21. // 在RightSide中使用自己的上下文context跳转就是局部跳转
    22. Navigator.push(
    23. context,
    24. MaterialPageRoute(builder: (context) => XXX(), fullscreenDialog: true),
    25. );
    26. // 在RightSide中如果想使用全局跳转, 可以预先将顶层组件的上下文储存在全局变量中, 使用顶层的上下文跳转即为全局跳转
    27. Navigator.push(
    28. global.homeContext,
    29. MaterialPageRoute(builder: (context) => AttendClass()),
    30. );