Я создал экран входа в систему, который извлекает данные из базы данных supabase, и пользователь может войти в систему, когда эти данные для входа станут верными, и пользователь сможет войти в систему.
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
}
},
В If/Else есть только одна проблема, где if (response.error==null) выдает эту ошибку 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'.





Не делайте этого, лучше оберните свой код в блок try-catch, подобный этому
try {
final supabase = Supabase.instance.client;
final email = emailController.text;
final password = passwordController.text;
// Authenticate user with Supabase
await supabase.auth.signInWithPassword(
email: email,
password: password,
);
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'),
),
],
);
},
);
} on AuthException catch (e) {
print('Login failed: ${e.message}');
}
обратитесь к этому https://pub.dev/documentation/supabase/latest/supabase/AuthException-class.html