1 、问题

用Flutter写了页面跳转,提示错误如下

Navigator operation requested with a context that does not include a Navigator.

 
2 、我的代码

    void main() {
      runApp(MyApp1());
    }
     
     
    class MyApp1 extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'open url',
          home: Scaffold(
              appBar: AppBar(
                title: Text('hello flutter'),
              ),
              body: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  FlatButton(
                    child: Text("go to new page"),
                    textColor: Colors.blue,
                    onPressed: () {
                        Navigator.push(context, MaterialPageRoute(
                          builder:(context) => NewPage()));
                    },
                  ),
                ],
     
              ),
          ),
        );
      }
    }
     
     
    class NewPage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
          return Scaffold(
            appBar: AppBar(
                title: Text("hello word"),
            ),
            body: Center(
               child: Text("this is new page"),
            ),
          );
      }
    }
更多请见:http://www.mark-to-win.com/tutorial/51852.html

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐