Difference between onPopPage and popRoute

Viewed 199

I´m using Navigation 2.0 for flutter navigation development, however, there´s only one topic for me to understand it properly. I´m using a custom RootBackButtonDispatcher:

class AppBackButtonDispatcher extends RootBackButtonDispatcher {
  final AppRouteDelegate routerDelegate;

  AppBackButtonDispatcher({
    @required this.routerDelegate,
  }) : super();

  @override
  Future<bool> didPopRoute() {
    return routerDelegate.popRoute();
  }
}

When pressing the back button, the function that gets called is (a function that is inside my AppRouteDelegate):

 @override
  Future<bool> popRoute() {
    if (_canPop()) {
      _removePage(viewModel.pages.last);
      viewModel.rebuild;

      return SynchronousFuture(true);
    }

    return SynchronousFuture(false); // This will exit the application
  }

The previous code handles properly the back button functionality, but the Navigator´s onPopPage never gets called:

 @override
  Widget build(BuildContext context) => Navigator(
        key: navigatorKey,
        onPopPage: _onPopPage, => WHY DON´T YOU GET CALLED!
        pages: _buildPages(),
      );

Am I handling this code in a wrong way, or by adding the custon back button dispatcher, the forementioned function never gets called?

0 Answers
Related