0

我正在尝试CupertinoNavigationBar使用 endDrawer 添加,我尝试在尾随上添加手势检测器,但不起作用,显示如下:

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 中的脚手架上下文

应用栏:

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();

4

1 回答 1

4

这是您尝试使用Scaffold.of(context). 您应该阅读错误日志。

从传递给的上下文开始,找不到 Scaffold 祖先Scaffold.of()

要解决您的问题,请使用Builder小部件生成新的上下文。

trailing: Builder(
            builder: (context) {
              return IconButton(
                icon: Icon(Icons.menu),
                onPressed: () {
                  Scaffold.of(context).openEndDrawer();
                },
              );
            },
          ),
于 2019-07-04T06:09:16.227 回答