Flutter - go_router - Shared scaffolding in child nested navigation

Viewed 114

I'm trying to set up a structure like this on go_router.

Routing

I'm trying to do it by looking at the shared scaffold and nested navigation examples, but when I go down to the bottom child, I have to write the parameter of the first pages.

I just need help on how to set up the routing build. I don't want to send the parameter of the first pages when I go down to the subpages is that possible?

class AppRouter {
  UserController userService = locator<UserController>();
  late final router = GoRouter(
    errorPageBuilder: (context, state) {
      return MaterialPage<void>(
        key: state.pageKey,
        child: Scaffold(body: Center(child: Text('${state.error}'))),
      );
    },
    redirect: (state) {
      if (state.subloc == '/' || state.subloc == '/yukleniyor' || state.subloc == '/login' || state.subloc == '/main_view' || state.subloc == '/veri_aliniyor') {
        debugPrint('========================>      INITIAL STATUS YÖNLENDİRME ${userService.status} ');
        final isLoadYukleniyorView = state.subloc == '/yukleniyor';
        final isLoadLoginView = state.subloc == '/login';
        final isLoadMainView = state.subloc == '/main_view';
        final isLoadVeriAliniyorView = state.subloc == '/veri_aliniyor';

        if (!isLoadYukleniyorView && userService.status == AuthType.yukleniyor) return state.namedLocation('yukleniyor');
        if (!isLoadLoginView && userService.status == AuthType.dogrulanmamis) return state.namedLocation('login');
        if (!isLoadVeriAliniyorView && userService.status == AuthType.dataAliniyor) return state.namedLocation('veri_aliniyor');
        if (!isLoadMainView && (userService.status == AuthType.dogrulandi || userService.status == AuthType.internetOlmadanDogrulanmis)) return '/main_view/initial';
        return null;
      } else {
        return null;
      }
    },
    refreshListenable: userService,
    debugLogDiagnostics: true,
    routes: [
      GoRoute(
        name: '/splash',
        path: '/',
        builder: (context, state) => const Scaffold(body: Center(child: Text('Splash Screen'))),
      ),
      GoRoute(
        name: '/yukleniyor',
        path: '/yukleniyor',
        builder: (context, state) => const YukleniyorView(),
      ),
      GoRoute(
        name: '/veri_aliniyor',
        path: '/veri_aliniyor',
        builder: (context, state) => const VeriAliniyorView(),
      ),
      GoRoute(
        name: '/login',
        path: '/login',
        builder: (context, state) => const LoginView(),
      ),
      GoRoute(
        name: '/main_view',
        path: '/main_view/:screen(initial|calisan_denetimleri_view|personel_denetim_analizi_view|calisan_risk_analizi_view)',
        pageBuilder: (context, state) {
          final param = state.params['screen'];
          late Widget body;
          late String appBarTitle;
          if (param != 'initial') {
            // Param initial değilse uygulama içinde geziniyor.
            if (param == 'calisan_denetimleri_view') {
              body = const CalisanDenetimleriView();
              appBarTitle = 'Çalışan Denetim Bilgi Sistemi';
            } else if (param == 'personel_denetim_analizi_view') {
              body = const PersonelDenetimAnalizView();
              appBarTitle = 'Personel Denetim Analizi';
            } else if (param == 'calisan_risk_analizi_view') {
              body = const CalisanRiskAnaliziView();
              appBarTitle = 'Çalışan Risk Analizi';
            }
          } else {
            // Param initial ise uygulama yeni açıldı initial sayfayı belirliyelim
            if (userService.status == AuthType.dogrulandi && (userService.personelBilgi.turId == 989 || userService.personelBilgi.turId == 1100)) {
              body = const PersonelDenetimAnalizView();
              appBarTitle = 'Personel Denetim Analizi';
            } else {
              body = const CalisanDenetimleriView();
              appBarTitle = 'Çalışan Denetim Bilgi Sistemi';
            }
          }
          return FadeTransitionPage(
            key: state.pageKey,
            child: MainView(appBarTitle: appBarTitle, body: body),
          );
        },
        routes: [
          GoRoute(
            name: 'calisan_denetim_detay',
            path: 'calisan_denetim_detay',
            pageBuilder: (context, state) {
              int index = int.parse(state.queryParams['tab'] ?? '0');
              return FadeTransitionPage(
                key: state.pageKey,
                child: CalisanDenetimDetayMainView(index: index),
              );
            },
          ),
        ],
      ),
    ],
  );
}
0 Answers
Related