Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WillPopScope should I use return Future.value(true) after Navigator.pop

Tags:

flutter

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.

like image 216
Guy Luz Avatar asked Jan 01 '19 13:01

Guy Luz


2 Answers

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.

like image 92
Guy Luz Avatar answered Oct 24 '22 10:10

Guy Luz


onWillPop: () {
    Navigator.pop(context, 'ANY RETURN VALUE');
    return new Future(() => false);
  },
like image 37
Nifal Nizar Avatar answered Oct 24 '22 09:10

Nifal Nizar