I Wrapped my Widget tree with WillPopScope and I want to show Popup Dialog which shows users to Exit from the app or not but at the same time, I have to use if()else{} condition. When I use this condition my logic works fine but didn't return anything.
What is trying to Achieve:
when someone clicks on the back press it checks the condition if it's true then Popup Appear and after the popup disappears it return some boolean value to WillPopScope but when the popup disappears WillPopScope didn't do anything.
I tried different solutions but didn't work for me.
Here's my code back press
backPressed() {
if (isCollapsed) {
showDialog(
context: context,
builder: (context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
clipBehavior: Clip.antiAliasWithSaveLayer,
backgroundColor: Colors.white,
actionsPadding: EdgeInsets.symmetric(horizontal: 12.0),
title: Text(
'Are you sure you want to close this App?',
style: TextStyle(
color: Colors.black.withOpacity(0.7),
),
),
actions: <Widget>[
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
child: Text('Exit'),
onPressed: () {
Navigator.of(context).pop(true);
print("Return True");
return true;
}),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
child: Text('Dismiss'),
onPressed: () {
Navigator.of(context).pop(false);
print("Return False");
return false;
}),
],
),
);
} else {
menuButton();
return false;
}
}
WillPopScope Code is:
WillPopScope(
onWillPop: () async => backPressed(),
child:
question from:
https://stackoverflow.com/questions/65915818/flutter-willpopscope-await-for-popup-disappear 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…