PopScope still fails on GoRouter root routes — a MethodChannel workaround

Starting with GoRouter v13+, PopScope does not reliably handle the Android back button on root routes. That limitation is documented in flutter/flutter#140869, which is now closed. Cousin issues such as #153546 and #112765 are worth reading if you are still hitting edge cases. I published go_router_back_handler 1.0.2 on pub.dev under the jehadurre.me publisher to work around this. It intercepts the back button on the Android side through a MethodChannel, then decides whether to pop, walk a route hierarchy you give it, or show an exit confirmation on a root route. The Dart side GoRouterBackHandler.initialize( navigatorKey: rootNavigatorKey, routeHierarchy: { '/profile': '/home', '/settings': '/home', '/details': '/list', }, rootRoutes: ['/', '/login', '/home'], ); Pass the same rootNavigatorKey into GoRouter. Call GoRouterBackHandler.dispose() in dispose(). A longer copy-pasteable snippet is in this gist and in the package README. The

PopScope still fails on GoRouter root routes — a MethodChannel workaround

Starting with GoRouter v13+, PopScope does not reliably handle the Android back button on root routes. That limitation is documented in flutter/flutter#140869, which is now closed. Cousin issues such as #153546 and #112765 are worth reading if you are still hitting edge cases.

I published go_router_back_handler 1.0.2 on pub.dev under the jehadurre.me publisher to work around this. It intercepts the back button on the Android side through a MethodChannel, then decides whether to pop, walk a route hierarchy you give it, or show an exit confirmation on a root route.

The Dart side

GoRouterBackHandler.initialize(
  navigatorKey: rootNavigatorKey,
  routeHierarchy: {
    '/profile': '/home',
    '/settings': '/home',
    '/details': '/list',
  },
  rootRoutes: ['/', '/login', '/home'],
);

Pass the same rootNavigatorKey into GoRouter. Call GoRouterBackHandler.dispose() in dispose(). A longer copy-pasteable snippet is in this gist and in the package README.

The native step is not optional

A Dart-only paste will not intercept the back button. You have to update MainActivity.kt.

  • The channel name must be exactly com.gorouter.back_handler/back_button.
  • After changing native code, do a full restart, not a hot reload.
  • The full Kotlin is in the package README. Copy it carefully and keep your own application id in the package line.

If the app exits immediately with no confirmation, the usual cause is a missing or mismatched MainActivity.kt.

What this post is not claiming

The live pub.dev score on 28 November 2026 was 140/160 (static analysis and outdated dependencies still cost points). I am not going to pretend it is 160/160. A v1.0.3 that closes that gap would be a later, approval-gated release.

Install:

dependencies:
  go_router_back_handler: ^1.0.2

Share