Auto Route Issue in nested navigation back method

31 Views Asked by At

I shared the solution below!

I am using auto_route package, in nested navigation I get error which says:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: NoSuchMethodError: Class 'TabsRouter' has no instance getter 'identifier'. E/flutter ( 5578): Receiver: Instance of 'TabsRouter'

@AutoRouterConfig(replaceInRouteName: "View,Route")
    class AppRouter extends _$AppRouter {
      @override
      List<AutoRoute> get routes => [
            AutoRoute(
              page: HomeRoute.page,
              path: "/home",
              initial: true,
              children: [
                AutoRoute(page: UserRoute.page, path: "user", initial: true),
                AutoRoute(page: SettingsRoute.page, path: "settings"),
              ],
            ),
            AutoRoute(
              page: UserDetailRoute.page,
            ),
          ];
    }
1

There are 1 best solutions below

0
Emirhan Selim Uzun On

7.8.4 works fine.
Make sure you omit the ^ in your pubspec otherwise on ugprade it will resolve to 7.8.5 auto_route: 7.8.4

The difference which causes the problem is:

  • routing_controller.dart v7.8.4:

    void _removeTopRouterOf(Key? key) {
        for (final ctr in List.unmodifiable(_childControllers).reversed) {
            if (ctr.key == key) {
              _childControllers.remove(ctr);
              break;
            }
          }
        }
    
  • routing_controller.dart v7.8.5:

    void _removeTopRouterOf(Key? key) {
        for (final ctr in List.unmodifiable(_childControllers).reversed) {
            if (ctr.identifier == key) {
              _childControllers.remove(ctr);
              break;
            }
          }
        }