marcglasberg / back_button_interceptor

Flutter Package: May be used to intercept the Android back-button, as an alternative to `WillPopScope`.
BSD 2-Clause "Simplified" License
105 stars 21 forks source link

Browser back button doesn't work #13

Closed nolandg closed 2 years ago

nolandg commented 2 years ago

myInterceptor() is never called when I press the web browser's back button in my Flutter PWA. Is this intended? Does this only work for Android device back button? Is there any other way to every intercept browser back button? WillPopScope solution doesn't get called either.

Thanks!

marcglasberg commented 2 years ago

This package was created before Flutter for Web even existed, so yes it was intended for the Android back button only.

I don't have much experience with the browser's back button yet, but I'd say if not even WillPopScope works, then the browser's back button is not meant to work like the Android back button anyway.

Suppose you are in some website and navigates to a Flutter web page, opens a dialog, then presses the browser back button. What is the expected result? Should it close the dialog or should it navigate back to the previous website? I'd say in the web you should navigate to the previous website, while in Android the expected behavior should be closing the dialog.

So, I'd say the semantics of the back button is different in the web and in Android, even though they are both called "back button". That's why probably the browser back button is not related to WillPopScope. Of course, this is all a supposition of mine, and I may be completely wrong. In any case I'd suggest to you that you should have a look into Navigator 2, which certainly lets you control what happens when using the browser's back button:

https://medium.com/flutter/learning-flutters-new-navigation-and-routing-system-7c9068155ade