getRouterConfig method

GoRouter getRouterConfig(
  1. AppAttributes appAttributes,
  2. AnimationController controller,
  3. void handleChangedPageIndex(
    1. int value
    ),
  4. int currentPageIndex,
)
inherited

Implementation

GoRouter getRouterConfig(
  AppAttributes appAttributes,
  AnimationController controller,
  final void Function(int value) handleChangedPageIndex,
  int currentPageIndex,
) {
  return GoRouter(
    navigatorKey: _rootNavigatorKey,
    initialLocation: _getInitialLocation(appAttributes, currentPageIndex),
    routes: <RouteBase>[
      StatefulShellRoute.indexedStack(
        builder:
            (
              BuildContext context,
              GoRouterState state,
              StatefulNavigationShell navigationShell,
            ) {
              // Return the widget that implements the custom shell (in this case
              // using a BottomNavigationBar). The StatefulNavigationShell is passed
              // to be able access the state of the shell and to navigate to other
              // branches in a stateful way.
              return Home(
                handleChangedPageIndex: handleChangedPageIndex,
                scaffoldKey: scaffoldKey,
                footer: getFooter(appAttributes),
                appAttributes: appAttributes,
                controller: controller,
                navigationShell: navigationShell,
              );
            },
        branches: createBranches(appAttributes),
      ),
    ],
    redirect: (BuildContext context, GoRouterState state) {
      var allValidRoutes = appAttributes.screenConfigurations
          .getAllValidRoutes();
      if (!allValidRoutes.contains(state.fullPath)) {
        return appAttributes.screenConfigurations
            .getErrorPagesConfig()
            .first
            .getRoutingName();
      }
      // no need to redirect at all
      return null;
    },
  );
}