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

v6.0.1 back button interception issues #22

Closed Lorenzohidalgo closed 4 months ago

Lorenzohidalgo commented 1 year ago

Hi,

following #21 I migrated the application to null-safety and upgraded to the last version of flutter and the package version but the issue still continues. It looks like the interceptor function is being executed, but the navigation pop is not being intercepted.

Here are some details:

YAML config:

environment:
  sdk: '>=2.17.0 <=3.0.4'

dependencies:
  # some additional packages
  back_button_interceptor: ^6.0.1

Flutter Doctor:

[√] Flutter (Channel stable, 3.0.4, on Microsoft Windows [Versi¢n 10.0.19044.1806], locale es-ES)
    • Flutter version 3.0.4 at C:\DEVELOPMENT\SRC\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 85684f9300 (11 days ago), 2022-06-30 13:22:47 -0700
    • Engine revision 6ba2af10bb
    • Dart version 2.17.5
    • DevTools version 2.12.2

My interceptor implementation:

  // Some code
  BackButtonInterceptor.add(myInterceptor, context: this.context);
  // Some more code

  bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) {
    if (info.ifRouteChanged(context)) {
      Navigator.of(context).pop();
      return true;
    }
    if (state.updatedSchedule) {
      add(ScheduleEditGoBackNeedConfirmation());
    } else {
      add(ScheduleEditGoBack());
    }
    return true;
  }

  @override
  Future<void> close() async {
    BackButtonInterceptor.remove(myInterceptor);
    super.close();
  }

The navigation works correctly when executed through the in-app nav buttons. The myInterceptor function is being executed as expected, but the navigation pop is not intercepted (it's executed anyways)

Lorenzohidalgo commented 1 year ago

@marcglasberg, any idea on how I could solve/troubleshoot this?

marcglasberg commented 1 year ago

@Lorenzohidalgo Hey Lorenzo, sorry for the delay. I can try, but you haven't given me enough information. Can you please provide a very simple (as simple as possible), complete and runnable code (with man method and all) that demonstrates the problem you are having? If I can reproduce it here with a very simple code, then I should be able to tell you what the problem is.

Thank you!

marcglasberg commented 4 months ago

Closed because of no feedback.