【问题标题】:Has a Cupertino Navigation to show the app bar but need have end drawer有一个库比蒂诺导航来显示应用程序栏,但需要有结束抽屉
【发布时间】:2019-11-14 18:02:45
【问题描述】:

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

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

【问题讨论】:

    标签: ios flutter dart flutter-layout flutter-cupertino


    【解决方案1】:

    这是您尝试使用 Scaffold.of(context) 时的常见问题。您应该阅读错误日志。

    从之前的上下文中找不到 Scaffold 祖先 传递给Scaffold.of()

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

    trailing: Builder(
                builder: (context) {
                  return IconButton(
                    icon: Icon(Icons.menu),
                    onPressed: () {
                      Scaffold.of(context).openEndDrawer();
                    },
                  );
                },
              ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-19
      • 2021-10-01
      • 2022-12-18
      • 2019-09-15
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2016-01-04
      相关资源
      最近更新 更多