【发布时间】:2021-08-27 18:14:29
【问题描述】:
我正在为用户创建/日志,但我有多个错误,这是我的代码,在我的错误之后: 登录控制器.dart:
String? _mail;
String? _password;
String? _prenom;
String? _nom;
_handlelog(){
if(_mail != null){
if(_password != null){
if(_log == true){
//se connecter
FirebaseHelper().handleSignIn(_mail, _password).then(((User user) {
print("Nous avons un user");
})).catchError((error){
alerte(error.toString());
});
}else{
if(_prenom != null){
if(_nom != null){
//créer un compte avec les données de l'utilisateur
FirebaseHelper().handleCreate(_mail, _password, _prenom, _nom).then(((User user) {
print("Nous avons pu créer un user");
})).catchError((error){
alerte(error.toString());
});
}else{
//Alert nom
alerte("veuillez entrer un nom pour continuer");
}
}else{
//Alert prenom
alerte("veuillez entrer un prenom pour continuer");
}
}
}else{
//Alert password
alerte("le mot de passe est vide");
}
}else{
//Alert mail
alerte("l'adresse mail est vide");
}
}
FirebaseHelper.dart:
class FirebaseHelper {
//Authentification
final auth = FirebaseAuth.instance;
Future<UserCredential> handleSignIn(String mail, String password) async{
final UserCredential user = await auth.signInWithEmailAndPassword(email: mail, password: password);
return user;
}
Future<UserCredential> handleCreate(String mail, String password, String prenom, String nom) async{
final UserCredential credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: mail, password: password);
String uid = credential.user!.uid;
Map<String, String> map = {
"uid" : uid,
"prenom" : prenom,
"nom" : nom,
};
addUser(uid, map);
return credential;
}
//database
static final base = FirebaseDatabase.instance.reference();
// ignore: non_constant_identifier_names
final base_user = base.child("users");
addUser(String uid, Map map){
base_user.child(uid).set(map);
}
}
在 LoginController.dart 我有
The argument type 'String?' can't be assigned to the parameter type 'String'.
The argument type 'Null Function(User)' can't be assigned to the parameter type 'FutureOr<dynamic> Function(UserCredential)'.
我不知道我能做什么,我在文档上搜索了很长时间,在这个网站上找到了更多细节,但我什么也没找到,我很绝望
【问题讨论】:
标签: firebase flutter dart firebase-authentication