The questions I’m going to ask are really connected. The idea is pop back on previous screen from alert and send there a value, but as it turned out there are some difficulties with it.
I use cool_alert
package in these pieces.
- I can show alert, but how after it pop back on previous screen and send a value?
onPressed: () { ... _coolAlert(context); },
if I use the following then why the alert even doesn’t show?
onPressed: () { ... _coolAlert(context); Navigator.pop(context, true); },
where _coolAlert defined as
_coolAlert(Build Context context) { CoolAlert.show( context: context, type: CoolAlertType.success, text: "Your transaction was successful!", onConfirmBtnTap: () { debugPrint('success'); }, ); }
the return type of show
is Future<dynamic>
- and finally if change it like this, then why the receiving value on previous screen is null?
_coolAlert(Build Context context) { CoolAlert.show( context: context, type: CoolAlertType.success, text: "Your transaction was successful!", onConfirmBtnTap: () { debugPrint('success'); }, Navigator.pop(context, true); ); }
3
Answers
bool? callBack= await _coolAlert(context);
Cuz dialog returns future, you have to wait for it
There is one more param which is need for this to work.
closeOnConfirmBtnTap: false,
This will allow you to manually call
pop
method with a value. Here is a sample codeOutput
simply add await
in your code
2.