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
Flutter提示之Navigator operation requested with a context that does not include a Navigator
最新推荐文章于 2022-03-07 16:14:35 发布