how do I know if a page is pushed or not in navigation stack?


let say I have 2 pages, PageA and PageB.

if a user tap a button in PageA then it will move to PageB using the code below


so as a result, there is back button in the top left app bar in PageB

my question is …..

how do I know if a page is pushed or not? I want to do something only if there is a back button in the appbar in a page


You can use this:

final hasPagePushed = Navigator.of(context).canPop();

This is actually what the flutter’s AppBar is using to know whether or not it should display the back button.

Answered By – Valentin Vignal

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *