需要关闭包含SimpleDialog颤振的模态底部工作表

时间:2018-10-16 17:35:32

标签: dart flutter

在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 
      }
    });
}

在“简单对话框”中执行操作时,我需要关闭模式底部,但是,当返回值为null时,我不需要显示简单的模式(我只是忽略该动作)并关闭模式底部工作表。

感谢您的反馈。

1 个答案:

答案 0 :(得分:0)

解决方案只需设置Navigator.pop(context,DialogActions.cancel);否则,返回Container();

然后进入showUserStatusDialog,然后使用此Navigator.pop(context);