【问题标题】:Flutter navigate between Dart files在 Dart 文件之间进行 Flutter 导航
【发布时间】:2020-06-20 14:34:40
【问题描述】:

你好,我正在尝试制作一个颤振程序,但程序非常慢,因为我在同一个小部件中制作所有内容,有人知道如何使用 po Navigator 从 Dart 文件中更改

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    第一个飞镖文件:

    class FirstRoute extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('First Route'),
          ),
          body: Center(
            child: RaisedButton(
              child: Text('Open route'),
              onPressed: () {
               Navigator.push(
               context,
               MaterialPageRoute(builder: (context) => SecondRoute()),
              );},
            ),
          ),
        );
      }
    }
    

    第二个飞镖文件:

    class SecondRoute extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text("Second Route"),
          ),
          body: Center(
            child: RaisedButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text('Go back!'),
            ),
          ),
        );
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-05
      • 2020-12-26
      • 2019-07-09
      • 1970-01-01
      • 2022-01-05
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多