【问题标题】:Need to close a Modal Bottom Sheet that contains a SimpleDialog flutter需要关闭包含 SimpleDialog 颤振的模态底页
【发布时间】:2019-03-21 07:37:30
【问题描述】:

当在 SimpleDialog 上执行操作时,我需要一种方法来关闭模态底部工作表,我有这样的事情:

Widget _getActionsMenu() {
    return Container(
        padding: EdgeInsets.fromLTRB(0.0, 0.0, 10.0, 0.0),
        child: IconButton(
          icon: Icon(Icons.arrow_forward_ios),
          color: Colors.grey[400],
          onPressed: () {
            showModalBottomSheet<void>(
                context: context,
                builder: (BuildContext context) {
                  return new Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      new ListTile(
                        leading: new Icon(Icons.train),
                        title: new Text(Utility.format(
                            Language.of(context).takePlace, [_place.title])),
                        onTap: () {
                          showUserStatusDialog<DialogActions>(
                              context: context,
                              child: this._getCurrentUserPlaceStatus());
                        },
                      ),
                      new ListTile(
                        leading: new Icon(Icons.share),
                        title: new Text(Language.of(context).share),
                        onTap: () {
                          Share.share(Utility.format(
                              Language.of(context).placeInvitation,
                              [_place.title, 'GooglePlay']));
                        },
                      ),
                    ],
                  );
                });
          },
        ));
}

Widget _getCurrentUserPlaceStatus() {
    //Here are an API call to get some data, we will name this variable as data
    var data = getAPIData();
    if (data == null) return null; //Also here I need a way to not show the modal and close the modal bottom sheet
    return SimpleDialog(
                title: Text(data['getCurrentUserPlaceStatus']['status'] == 2
                    ? 'You are going to '
                    : 'You are in ' +
                        data['getCurrentUserPlaceStatus']['place']['name']),
                children: <Widget>[
                  FlatButton(
                      child: Text(Language.of(context).no),
                      onPressed: () {
                        Navigator.pop(context, DialogActions.cancel);
                      }),
                  FlatButton(
                      child: Text(Language.of(context).yes),
                      onPressed: () {
                        Navigator.pop(context, DialogActions.agree);
                      })
                ],
              );
}

void showUserStatusDialog<T>({BuildContext context, Widget child}) {
    showDialog<T>(
      context: context,
      builder: (BuildContext context) => child,
    ).then<void>((T value) {
      if (value != null) {
          //Here I need to close the Modal Bottom 
      }
    });
}

我需要在简单对话框中执行动作时关闭模态底部,而且当返回为空时,我不需要显示简单模态(我的意思是忽略动作)并关闭模态底部表。

如有任何反馈,我将不胜感激。

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    解决方法就是设置 Navigator.pop(context, DialogActions.cancel);否则,返回 Container();

    然后进入showUserStatusDialog,进入then,使用这个Navigator.pop(context);

    【讨论】:

      猜你喜欢
      • 2021-08-11
      • 2019-03-10
      • 2021-02-18
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2021-01-14
      相关资源
      最近更新 更多