Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_interceptor is being called before closing dialogs #4

Closed
HTMHell opened this issue Jun 21, 2020 · 3 comments
Closed

_interceptor is being called before closing dialogs #4

HTMHell opened this issue Jun 21, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@HTMHell
Copy link

HTMHell commented Jun 21, 2020

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
Copy link
Owner

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
Copy link
Owner

@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: 2e5dced

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

@HTMHell
Copy link
Author

HTMHell commented Jun 22, 2020

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;

@marcglasberg marcglasberg added the enhancement New feature or request label Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants