I was able to override the back button onPressed behavior using WillPopScope
. Now, whenever I press the device back button
or the default AppBar back button
, the code inside onWillPop
runs as expected.
The problem now is that I want to have my own custom buttons to navigate backward, but Navigator.of(context).pop()
doesn't check the WillPopScope as if it doesn't exist. I also tried Navigator.of(context).maybePop()
, but I get the same behavior.
- Is there a way to simulate the system's back behavior or call it somehow?
- I know I can just call the same function that is called by onWillPop() manually upon pressing my custom back button, but I was eager to find a cleaner method, as in the future I could easily forget doing that and cause bugs.
CodePudding user response:
In simple cases, when you need to intercept the Android back-button, you usually add WillPopScope
to your widget tree. However, when developing stateful widgets that interact with the back button, it's more convenient to use the BackButtonInterceptor
.
For more details check this link: https://pub.dev/packages/back_button_interceptor
CodePudding user response:
While using StateFullWidget, It is more convenient to use BackButtonInterceptor
.
Hope this will Helpful.
For more Details Please check this:
[1]: https://pub.dev/packages/back_button_interceptor