Reputation: 2213
I am using the Awesome Dialog in my flutter application but when I click on OK it just navigates to another screen and doesn't close. here is my code.
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();
}
}
Upvotes: 0
Views: 3224
Reputation: 9
I am trying to use the Awesome Dialogue and then use the property "useRootNavigator" and set it to 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();
Upvotes: 1
Reputation: 7990
Although doc for this library says,
Function that handle click of positive Button, closing the dialog is handled internally.
UPDATE: I have tried it myself and it works fine approach I used, I took a button to open dialog,
RaisedButton(
child: Text("ok",),
onPressed: () {
open();
},
),
Since dialog closing is handled by default by the library I used Navigator.pop(context);
this to go back to the previous screen using 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();
}
Note: I navigate to screen which is having dialog by Navigator.pushNamed
. So if Navigator.pop(context);
is called it comes back to this screen only.
Navigator.pushNamed(context, RouteName.ReportScreen);
Output:
Upvotes: 1
Reputation: 11634
I am unable to replicate your issue. I used a simple RaisedButton
upon tapping on it opens AwesomeDialog
. Then tapping on OK
button of the dialog closes it properly. I also tested by adding a navigation upon ok button tap that closes the dialog and navigates to next screen. Code I used:
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();
}
Console output:
I/flutter (13279): Dialog Dissmiss from callback
I/flutter (13279): Dialog Dissmiss from callback
Hope this helps.
Upvotes: 1