How to use multiple navigators

后端 未结 1 1636
萌比男神i
萌比男神i 2020-12-17 06:04

I currently have a MaterialApp in my flutter application which makes the use of the Navigator extremely easy, which is great. But, I\'m now trying

1条回答
  •  时光说笑
    2020-12-17 06:24

    You can create new Navigator for each page. As a reference check CupertinoTabView

    Or simple example:

    import 'package:flutter/material.dart';
    
    class Home extends StatelessWidget {
      Navigator _getNavigator(BuildContext context) {
        return new Navigator(
          onGenerateRoute: (RouteSettings settings) {
            return new MaterialPageRoute(builder: (context) {
              return new Center(
                child: new Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    new Text(settings.name),
                    new FlatButton(
                      onPressed: () =>
                          Navigator.pushNamed(context, "${settings.name}/next"),
                      child: new Text('Next'),
                    ),
                    new FlatButton(
                      onPressed: () =>
                          Navigator.pop(context),
                      child: new Text('Back'),
                    ),
                  ],
                ),
              );
            });
          },
        );
      }
    
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          body: new Column(
            children: [
              new Expanded(
                child: _getNavigator(context),
              ),
              new Expanded(
                child: _getNavigator(context),
              ),
            ],
          ),
        );
      }
    }
    
    void main() {
      runApp(new MaterialApp(
        home: new Home(),
      ));
    }
    

    0 讨论(0)
提交回复
热议问题