redirectto shell route in flutter

38 Views Asked by At

it is for long time i try to fix this problem but i couldn't find the solution from the official videos and documentation. i wanna use redirect while the user logs in. It goes to the Shell route, not the homepage. What is the solution for that case as you know most of the developers use Shell route for landing page while user logging in .

please as soon as possible answer me

`final goRouteProvider = Provider((ref) { return GoRouter( routerNeglect: true, initialLocation: SplashPage.route, navigatorKey: Utils.mainNav, redirect: (context, state) async { var userLoggiedIn = await RememberUserPrefs.readUserInfo();

if (userLoggiedIn != null) {
  //i wanna return Shell route not landing page
  //it should be  GoRouter.of(Utils.mainNav.currentContext!).go('/homepage');
  //but it will return null

  return LandingPage.route;
} else {
  return SplashPage.route;
  }
  },
routes: [
GoRoute(
  parentNavigatorKey: Utils.mainNav,
  path: SplashPage.route,
  builder: (context, state) {
    return const SplashPage();
  },
),

GoRoute(
  parentNavigatorKey: Utils.mainNav,
  path: OnboardingPage.route,
  builder: (context, state) {
    return const OnboardingPage();
  },
),
GoRoute(
  path: SignIn.route,
  builder: (context, state) => const SignIn(),
),
GoRoute(
    path: SignUp.route, builder: (context, state) => const SignUp()),
//Bottom Appbar
ShellRoute(
 navigatorKey: Utils.tabNav,
 builder: (context, state, child) {
 return LandingPage(child: child);
  },
  routes: [
  GoRoute(
   parentNavigatorKey: Utils.tabNav,
   path: HomePage.route,
     pageBuilder: (context, state) {
      return const NoTransitionPage(
    child: HomePage(),
  );
 },
     ),
   GoRoute(
    parentNavigatorKey: Utils.tabNav,
   path: WebLinksPage.route,
   pageBuilder: (context, state) {
   return const NoTransitionPage(
    child: WebLinksPage(),
    );
   },
 ),
   ]),
 ]);
});`
0

There are 0 best solutions below