我正尝试在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
我已经尝试将密钥添加到脚手架并尝试使用该键打开,我也尝试在appbar中使用脚手架上下文
AppBar:
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();
答案 0 :(得分:1)
当您尝试使用Scaffold.of(context)
时,这是一个常见问题。您应该阅读错误日志。
从以下内容开始找不到脚手架祖先: 传递给
Scaffold.of()
要解决您的问题,请使用Builder
小部件来生成新的上下文。
trailing: Builder(
builder: (context) {
return IconButton(
icon: Icon(Icons.menu),
onPressed: () {
Scaffold.of(context).openEndDrawer();
},
);
},
),