0

Is there any ways to pass parameters(or extra Object) with sub routes?

When navigating PageA from PageB, type 'Null' is not a subtype of type 'int' error has occurred.

final _router = GoRouter(
  debugLogDiagnostics: true,
  initialLocation: '/',
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => TopPage(),
      routes: [
        GoRoute(
          path: 'a',
          builder: (context, state) {
            final res = state.extra as Map<String, dynamic>;
            return PageA(
              num: res['num'],
            );
          },
          routes: [
            GoRoute(
              path: 'b',
              builder: (context, state) {
                final res = state.extra as Map<String, dynamic>;
                return PageB(
                  numFromA: res['numFromA'],
                );
              },
            ),
          ],
        ),
      ],
    ),
  ],
);

enum AppRouter {
  pageA,
  pageB;
}

Masahiro Aoki
  • 815
  • 12
  • 22
  • Have you tried type-safe routes? https://pub.dev/documentation/go_router/latest/topics/Type-safe%20routes-topic.html – Rahul Feb 17 '23 at 07:58

0 Answers0