having trouble with login functionality with flutter supabase

  Kiến thức lập trình

I have created login screen which fetch data from supabase database and user can login when that login details got true and user can login.

onPressed: () async {
                    final supabase = Supabase.instance.client;
                    final email = emailController.text;
                    final password = passwordController.text;

                    // Authenticate user with Supabase
                    final response = await supabase.auth.signInWithPassword(
                      email: email,
                      password: password,
                    );

                    // ignore: unnecessary_null_comparison
                    if (response.error == null) {
                      // Show success popup
                      showDialog(
                        // ignore: use_build_context_synchronously
                        context: context,
                        builder: (BuildContext context) {
                          return AlertDialog(
                            title: const Text('Success'),
                            content: const Text('Login Successful'),
                            actions: <Widget>[
                              TextButton(
                                onPressed: () {
                                  Navigator.of(context).pop(); // Close dialog
                                  Navigator.pushReplacement(
                                    context,
                                    MaterialPageRoute(
                                      builder: (context) => const Home(),
                                    ),
                                  );
                                },
                                child: const Text('OK'),
                              ),
                            ],
                          );
                        },
                      );
                    } else {
                      // Login failed, handle the error
                      // ignore: avoid_print
                      print('Login failed: ${response.error!.message}');
                      // Show an error message to the user
                    }
                  },

There is only one problem in If/Else where if(response.error==null) gives this error The getter 'error' isn't defined for the type 'AuthResponse'. Try importing the library that defines 'error', correcting the name to the name of an existing getter, or defining a getter or field named 'error'.

New contributor

Pratik Trivedi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT