This is the 3rd time I am reporting this issue and 2 times I have given pull request for same but I don't know why this issue is always supressed.
The issue is so intermittent that it's very hard to catch.
The context we are passing and the context we are popping is same which pops screen behind the alert.
I gave solution to simply return context alert is using in onConfirmBtnTap function . onConfirmBtnTap(context)
We are always popping parent context in onConfirmBtnTap if we are defining that function , if function is null it pops context that alert widget has defined (child context of what we have passed)
// quickalert_buttons.dart
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
cancelBtn(context),
okayBtn(context), // the alert context not the parent which was passed
],
),
);
}
Widget okayBtn(context) { // the alert context not the parent which was passed
if (!options!.showConfirmBtn!) {
return const SizedBox();
}
final showCancelBtn = options!.type == QuickAlertType.confirm
? true
: options!.showCancelBtn!;
final okayBtn = buildButton(
context: context,
isOkayBtn: true,
text: options!.confirmBtnText!,
onTap: () {
options!.timer?.cancel();
// the alert context not the parent which was passed
// if options!.onConfirmBtnTap != null then user will use the parent context to pop which will pop current screen not alert
options!.onConfirmBtnTap != null
? options!.onConfirmBtnTap!()
: Navigator.pop(context);
});
if (showCancelBtn) {
return Expanded(child: okayBtn);
} else {
return okayBtn;
}
}
var res = await QuickAlert.show(
context: context,
width: width,
type: QuickAlertType.error,
title: 'Delete record',
widget: const Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Are you sure to remove this ?',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.grey,
fontSize: 13,
),
),
],
),
showCancelBtn: true,
showConfirmBtn: true,
onConfirmBtnTap: () {
Navigator.pop(context);
},
);