gpt4 book ai didi

dart - 需要关闭包含 SimpleDialog flutter 的 Modal Bottom Sheet

转载 作者:IT王子 更新时间:2023-10-29 07:05:57 25 4
gpt4 key购买 nike

我需要一种方法来在 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
}
});
}

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

我将不胜感激任何反馈。

最佳答案

解决方法就是设置 Navigator.pop(context, DialogActions.cancel);在其他情况下,返回 Container();

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

关于dart - 需要关闭包含 SimpleDialog flutter 的 Modal Bottom Sheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52841067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com