Is using return Future.value(false);
after Navigator.pop(context)
is the right way.
If I use
Navigator.pop(context, false)
and after it
return Future.value(true);
The application will show black screen after pressing the back button, and no errors in the Logcat.
But if I use the same code without the Navigator.pop(context)
or without the return Future.value(true);
everything will be fine, using return Future.value(false);
also works fine.
*Following a tutorial on Udemy that show return Future.value(true)
is ok.
I found the solution.
You should use return Future.value(false);
.
You navigated manually by using Navigator.pop(context)
, Future.value(true);
trigger another pop which can't be done because you already exist the page and this crashes the app.
OnWillPop expect a return so By using the return Future.value(false);
you tell the onWillPop that you handle the closing of the page here.
onWillPop: () {
Navigator.pop(context, 'ANY RETURN VALUE');
return new Future(() => false);
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With