[英]Awesome Dialog not closing in flutter app
我在我的 flutter 应用程序中使用Awesome Dialog但是当我点击 OK 它只是导航到另一个屏幕并且没有关闭。 这是我的代码。
Future requestSupport(String userid, String supportType, String duration) async {
final response =
await http.post('http://url/api/Support',
headers: {"Content-Type": "application/json",
'Accept': 'application/json',},
body: json.encode({'userid' : userid , 'supportType' : supportType, 'duration' : duration}));
if (response.statusCode == 200) {
showAlertDialogOnOkCallback();
}
}
void showAlertDialogOnOkCallback() {
AwesomeDialog(
context: context,
animType: AnimType.LEFTSLIDE,
dialogType: DialogType.SUCCES,
tittle: 'Success',
desc:
'You have been entered into the queue, press OK to go back.',
btnOkOnPress: () { },
btnOkIcon: Icons.check_circle,
onDissmissCallback: () {
debugPrint('Dialog Dissmiss from callback');
}).show();
}
}
虽然这个库的文档说,
处理正按钮点击、关闭对话框的功能是内部处理的。
更新:我自己试过了,我使用的方法很好,我用一个按钮打开对话框,
RaisedButton(
child: Text("ok",),
onPressed: () {
open();
},
),
由于对话框关闭是由库默认处理的,所以我使用了Navigator.pop(context);
使用btnOkOnPress
返回上一屏幕
void open() {
AwesomeDialog(
context: context,
dialogType: DialogType.INFO,
animType: AnimType.BOTTOMSLIDE,
tittle: 'Dialog Title',
desc:
'Dialog description here',
btnCancelOnPress: () {},
btnOkOnPress: () {
Navigator.pop(context);
}).show();
}
注意:我导航到Navigator.pushNamed
有对话框的屏幕。 所以如果Navigator.pop(context);
被称为它只返回到这个屏幕。
Navigator.pushNamed(context, RouteName.ReportScreen);
输出:
我无法复制您的问题。 我在点击它时使用了一个简单的RaisedButton
打开AwesomeDialog
。 然后点击对话框的OK
按钮将其正确关闭。 我还通过在确定按钮点击时添加导航来关闭对话框并导航到下一个屏幕来进行测试。 我使用的代码:
body: Center(
child: RaisedButton(
onPressed: () {
_openDialog();
},
child: Text('Tap')
)
)
void _openDialog() {
AwesomeDialog(
context: context,
animType: AnimType.LEFTSLIDE,
dialogType: DialogType.SUCCES,
tittle: 'Success',
desc:
'You have been entered into the queue, press OK to go back.',
btnOkOnPress: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => PageB()));
},
btnOkIcon: Icons.check_circle,
onDissmissCallback: () {
debugPrint('Dialog Dissmiss from callback');
}).show();
}
控制台输出:
I/flutter (13279): Dialog Dissmiss from callback
I/flutter (13279): Dialog Dissmiss from callback
希望这可以帮助。
我正在尝试使用Awesome Dialogue ,然后使用属性“useRootNavigator”并将其设置为 true。
AwesomeDialog(
useRootNavigator: true,
context: context,
animType: AnimType.LEFTSLIDE,
headerAnimationLoop: false,
dialogType: DialogType.SUCCES,
title: 'Go',
desc: 'Continue Adding ',
btnOkOnPress: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => Page2()));
},
btnOkIcon: Icons.receipt,
onDissmissCallback: () {
debugPrint('Dialog Dissmiss from callback');
},
btnOkText: "Add More members",
btnCancelOnPress: () {
Navigator.push(
context, new MaterialPageRoute(builder: (context) => Home()));
},
btnCancelIcon: Icons.home,
btnCancelText: "Go to Home Page")
..show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.