Flutter2.0 一定要区分好上线文(BuildContex

2021-08-17  本文已影响0人  壹点微尘

方案一:

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

context

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

  /// 弹窗提示 保存图片到本地
  _showCupertinoModalPopup() {
    showCupertinoModalPopup(
        context: context,
        builder: (_) {
          return CupertinoActionSheet(
            actions: <Widget>[
              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);
                },
              ),
            ],
          );
        });
  }
上一篇 下一篇

猜你喜欢

热点阅读