how can i convert this into go_route code in flutter

35 views Asked by At
ref.watch(currentUserAccountProvider).when(
  data: (user) {
    if (user != null) {
      return const HomeView();
    }
    return const SignUpView();
  },
  error: (error, st) => ErrorPage(
    error: error.toString(),
  ),
  loading: () => const LoadingPage(),
);

how can I convert it or do the same function with go_route package flutter

I tried to pass ref as parameter to read the value of the the provider and make redirection with the value but I can not find a way to read it

1

There are 1 answers

0
Arturo Romanelli On

Once you have defined the router, like

final _router = GoRouter(
  initialLocation: '/',
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => HomeView(),
    ),
    GoRoute(
      path: '/signUpPage',
      builder: (context, state) => SignUpView(),
    ),
  ],
);

you can navigate with

context.go('yourPath')

so you can change your code

if (user != null) {
context.go('/');
}
context.go('/signUpPage');;