kodecocodes / video-suf-materials

The projects and the materials that accompany the Supabase with Flutter course
Apache License 2.0
7 stars 6 forks source link

GoRouter not redirecting logged in user #4

Open gugaoliveira opened 1 year ago

gugaoliveira commented 1 year ago

With new GoRouter the app is not redirecting correct when user log in, it Is showing a black screen

kevindmoore commented 1 year ago

I am in the process of trying to upgrade gorouter. Going from 2.x to 6.x is a big step. I had to change a few things. I did get a black screen but it had an error that I fixed. I can't get it to load a new page. Working on it

lowbits commented 1 year ago

@kevindmoore i think i fixed the errors with black screen.

// main.dart
final router = ref.watch(routeProvider).router;

 initDatabase();
    return MaterialApp.router(
      routerConfig: router,
      debugShowCheckedModeBanner: false,
      title: 'Suddy',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
    );
  }

and instead of using state.namedRoutes (deprecated) use hardcoded

GoRoute(
          name: rootRouteName,
          path: '/',
          redirect: (context, state) => '/home'),

   redirect: (context, state) {
      const loginLoc = '/login';
      final loggingIn = state.subloc == loginLoc;
      final loggedIn = loginState.loggedIn;
      const rootLoc = '/';

      if (!loggedIn && !loggingIn) return loginLoc;
      if (loggedIn && (loggingIn)) return rootLoc;
      return null;
    },       

The error with no new site is pushed, is fixed by adding the whole router, not

routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
gugaoliveira commented 1 year ago

I fixed the problem, I migrated to grouter 6 too, and the problem with black screen is in this code

You have to use routerconfig:

Remove these 2 lines in main.dart

routeInformationParser: router.routeInformationParser, routerDelegate: router.routerDelegate,

The code of MaterialApp.router becomes this

return MaterialApp.router(       routerConfig: router,       debugShowCheckedModeBanner: false,       title: ref.watch(labelProvider),       theme: ThemeData(         primarySwatch: Colors.blue,         canvasColor: startGradientColor,       ),

🏢 Somos Cubo.network 🥇 Premio Ouro Gestão Empresarial - IQM 2012 🎓 Stanford University Certified in Entrepreneurship and Innovation (2014) 📈 Empresa parceira PAEX / Fundação Dom Cabral 📱 Mobile Developer - Apple, Google, Microsoft, AWS, Zebra Partners

🌎 https://www.smartretail.app 🌎 http://www.handcom.com.br

Em 16 de mar. de 2023 01:04 -0300, Kevin Moore @.***>, escreveu:

I am in the process of trying to upgrade gorouter. Going from 2.x to 6.x is a big step. I had to change a few things. I did get a black screen but it had an error that I fixed. I can't get it to load a new page. Working on it — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>