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

Not working as described #9

Closed HTMHell closed 3 years ago

HTMHell commented 3 years ago

If any function returns true, the combined result is true

I have the following case which is not working as described:

I have two widgets: MyScreen and CustomAppBar. In both widgets I initialize an interceptor. MyScreen has a Scaffold with a custom app bar widget I've made: CustomAppBar.

CustomAppBar:

  bool _interceptor(bool stopDefaultButtonEvent, RouteInfo info) {
    print('Custom AppBar');
    return true;
  }

MyScreen:

  bool _interceptor(bool stopDefaultButtonEvent, RouteInfo info) {
    print('My Screen');
    return false;
  }

In this case, the default back button behavior IS fired, and the route is being popped.

And the console looks like this:

Custom AppBar My Screen

If I return true in MyScreen too, then it is not fired. I tried using z-index, same result.

Version 4.4.0

marcglasberg commented 3 years ago

@HTMHell Hey Ariel, have you been able to make this work? Could you please specify why you closed this issue? Thanks.

HTMHell commented 3 years ago

@HTMHell Hey Ariel, have you been able to make this work? Could you please specify why you closed this issue? Thanks.

Hi, I'm not sure how it got solved. I did some refactoring (nothing to do with this issue) and then it suddenly started working as excepted. So I'm not sure what fixed it.

My refactoring included changing all screens to stateless while managing them with one parent stateful widget. So currently the parent screen and the appbar are stateful, and rest of the screens are stateless (the issue occurred in those screens). So it might have something to do with this.