我正在尝试使用 endDrawer 添加 CupertinoNavigationBar
,我尝试在尾部添加 Gesture Detector,但没有用,显示如下:
The following assertion was thrown while handling a gesture:
flutter: `Scaffold.of()` called with a context that does not contain a Scaffold.
flutter: No Scaffold ancestor could be found starting from the context that was passed to `Scaffold.of()`. This
flutter: usually happens when the context provided is from the same StatefulWidget as that whose build
我已经尝试将 key 添加到脚手架并尝试使用 key 打开,我也尝试在应用栏中使用脚手架上下文
应用栏:
Scaffold(
appBar: CupertinoNavigationBar(
transitionBetweenRoutes: true,
trailing: IconButton(
icon: Icon(Icons.menu),
onPressed: () {
Scaffold.of(context).openEndDrawer();
},),
actionsForegroundColor: Colors.white,
middle: Text('Lejour', style: TextStyle(color: Colors.white)),
backgroundColor: Theme.of(context).primaryColor),
endDrawer: DrawerMenu() // my own class,
body: // ...body
我希望 CupertinoNavigationBar 的尾随图标用
打开 endDrawer
Scaffold.of(context).openEndDrawer();
最佳答案
当您尝试使用 Scaffold.of(context)
时,这是一个常见问题。您应该阅读错误日志。
No Scaffold ancestor could be found starting from the context that was passed to
Scaffold.of()
要解决您的问题,请使用 Builder
小部件生成新的上下文。
trailing: Builder(
builder: (context) {
return IconButton(
icon: Icon(Icons.menu),
onPressed: () {
Scaffold.of(context).openEndDrawer();
},
);
},
),
关于ios - 有一个 Cupertino 导航来显示应用程序栏,但需要有结束抽屉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56880423/