Is device back button can call the pop() automaticly?

Viewed 160

I know this question can be little bit easy one, but I want to be sure for my navigation class. It must be valid.

I mean, I am routing my pages with pushNamed() function and pop after that I am using pop() function, but I am qurious about if user use the device back button, what will happen on the stack ?

And I also don't want to use popUntil function.

if user won't use the my AppBar button, if just use the device back button, is my XxxPage() will be on the stack or is it deleted automatically ?

2 Answers

Yes it does pop it from the stack, if you want, you can test the behavior by wrapping the screen with a WillPopScope() widget

for example:

 WillPopScope(
   onWillPop: () {
          print('POP');
          return Future.value(true);
        },
   child: YourChildWidget )

As described by Abdulrahman you can WillPopScope for the popup purpose or change something to pop.

WillPopScope(
   onWillPop: () {
          print('This will pop');
          Navigator.pop(context);
        }, child: Container(),
   )

you can set a leading for your scaffold to handle the back button of the scaffold manually also.

Related