【发布时间】:2018-07-30 18:47:48
【问题描述】:
我正在尝试使用颤振框架创建抽屉导航, 但每次运行时都会出现以下异常
另一个异常被抛出:导航器操作请求 不包含导航器的上下文。
那么解决办法是什么,有什么帮助吗?
我使用 Navigator 类如下
void main() {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new AppStates();
}
}
class AppStates extends State<MyApp> {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: new Scaffold(
appBar: AppBar(
title: Text("Application App Bar"),
),
drawer: Drawer(
child: ListView(
children: <Widget>[
ListTile(
title: Text("Next Page"),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => NextPage()));
},
)
],
),
),
),
);
}
}
NextPage类的代码是
class NextPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text("Next Page App Bar"),
),
),
);
}
}
【问题讨论】:
-
看看这个,这是你面临的吗? github.com/flutter/flutter/issues/15919
-
你解决了吗?