ios - 有一个 Cupertino 导航来显示应用程序栏,但需要有结束抽屉

标签 ios flutter dart flutter-layout flutter-cupertino

我正在尝试使用 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/

相关文章:

ios - 创建一个只有一个对角线的 UIView

ios - 项目中的哪个位置适合放置要在 iOS 应用程序中读取的资源文本文件?

ios - iPhone:默认隐藏 UITableView 搜索栏

flutter - 如何根据内容自动调整卡片 View 的大小

angular - 如何使用Dart在angular2中实现动画

flutter - 如何使showBottomSheet的特定部分可滚动

iphone - avplayer内存泄漏

flutter - Dart 中的 Lazy Singleton 与 Singleton

flutter - gitlab管道作业执行后执行codemagic构建

dart - 除主文件外无法编译任何文件