How to implement Authentication using Riverpod in Flutter?

567 Views Asked by At

I have three providers for login => email, password, login. then I am refreshing login provider which is a future provider and will call the login API. now I need to see if the provider returns success then I will need to navigate to next page. But .when() is not waiting for the refreshing to finish. Its logging "loading..." in the console.

`

ref.watch(email.notifier).state =
                                  emails.trim().toLowerCase();
                              ref.watch(password.notifier).state = passwords;
                              final loginstate = ref.refresh(login);
                              loginstate.when(data: ((data) {
                                // log(data + "here");
                                if (data == "Success") {
                                  context.go('/home');
                                }
                              }), error: (error, stackTrace) {
                                // log(error.toString() + "here");
                              }, loading: () {
                                log("loading....");
                              });

`

I need to Navigate to the Home page upon successful API call.

0

There are 0 best solutions below