Flutter2.0 一定要区分好上线文(BuildContext context),不然页面都没法关闭

方案一:

showCupertinoModalPopupbuilder: (BuildContext _context) {}_context只作用于modal弹窗的组件生命周期中,界面消失后,执行其他操作需要用到上下文的情况,一定要用最外边的上下文 context

context

方案二: 统一都使用最外层的content

  /// 弹窗提示 保存图片到本地
  _showCupertinoModalPopup() {
    showCupertinoModalPopup(
        context: context,
        builder: (_) {
          return CupertinoActionSheet(
            actions: [
              CupertinoActionSheetAction(
                child: Text(
                  '保存图片',
                  style: Theme.of(context).textTheme.headline4,
                ),
                onPressed: () {
                  CYNavigator.goBack(context);
                  _saveImg(context);
                },
              ),
              CupertinoActionSheetAction(
                child: Text(
                  '取消',
                  style: Theme.of(context).textTheme.bodyText1,
                ),
                onPressed: () {
                  CYNavigator.goBack(context);
                },
              ),
            ],
          );
        });
  }

你可能感兴趣的:(Flutter2.0 一定要区分好上线文(BuildContext context),不然页面都没法关闭)