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

_interceptor is being called before closing dialogs #4

Closed HTMHell closed 4 years ago

HTMHell commented 4 years ago

I have a screen where I set an interceptor in initState like so: BackButtonInterceptor.add(_interceptor);

If I open a dialog [showDialog(...)], and press the "back" button, I want the dialog to close and not fire the _interceptor method.

Currently the _interceptor is being called first, and only after the second "back", the dialog will be closed.

Of course I can set a flag that indicates if a dialog is opened, and make sure to set it for all dialogs on open&close, but I feel like a default behavior should be closing dialogs first.

marcglasberg commented 4 years ago

The whole point of the back_button_interceptor is giving you a direct, fine grained control of the back button. It's difficult to take the current route into consideration, because sometimes that's not what you want to do. So, yes, you should probably add a flag.

However, I could try to add a mode where the interceptor only works if the route it was created on is the current route. At the moment I am not sure that's possible. I'll investigate it.

marcglasberg commented 4 years ago

@HTMHell

Could you please test version 4.3.0? Read the notes section in the README file. It's not published yet, you have to use this in your pubspec.yaml file:

back_button_interceptor: git: url: https://github.com/marcglasberg/back_button_interceptor ref: 2e5dcedbe563de158f4883b4ae7e2ddca4416ed0

Could you please tell me if this solves the problem or not? Thanks.

HTMHell commented 4 years ago

I've tested, it works perfectly.

I've initialized the interceptor like that: BackButtonInterceptor.add(_interceptor, context: context);

And added the following to the beginning of the interceptor function: if (info.ifRouteChanged(context)) return false;