Reputation: 4009
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.
Upvotes: 7
Views: 6915
Reputation: 963
onWillPop: () {
Navigator.pop(context, 'ANY RETURN VALUE');
return new Future(() => false);
},
Upvotes: 5
Reputation: 4009
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.
Upvotes: 14