我正在尝试使用 Firebase 使用 Google 登录并尝试注册用户名和帐户。基本上我尝试执行的任何身份验证过程都会收到以下错误:
未处理的异常:“List
这是我的谷歌登录和使用用户名和密码注册的代码:
class LoginAccountBloc extends Bloc<LoginAccountEvent, LoginAccountState> {
LoginAccountBloc() : super(LoginAccountInitial()) {
on<LoginAccountSubmitted>(
(event, emit) async {
emit(LoginAccountSubmitting());
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: event.email,
password: event.password,
);
emit(LoginAccountSuccessful());
} on FirebaseAuthException catch (e) {
if (e.code == 'user-not-found') {
emit(LoginAccountFailure('No user found for that email.'));
} else if (e.code == 'wrong-password') {
emit(LoginAccountFailure('Wrong password provided for that user.'));
} else {
emit(LoginAccountFailure(e.toString()));
}
}
},
);
}
}
class RegisterAccountBloc
extends Bloc<RegisterAccountEvent, RegisterAccountState> {
RegisterAccountBloc() : super(RegisterAccountInitial()) {
on<RegisterAccountSubmitted>(
(event, emit) async {
print(event.username);
print(event.email);
print(event.password);
emit(RegisterAccountSubmitting());
if (event.username.isEmpty ||
event.email.isEmpty ||
event.password.isEmpty) {
emit(RegisterAccountFailure("All fields are required."));
return;
}
print('All fields are written');
try {
// Step 1: Create a new user with Firebase Authentication
final credential =
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: event.email,
password: event.password,
);
print('Added Credentials to FirebaseAuth');
} on FirebaseAuthException catch (e) {
if (e.code == 'weak-password') {
emit(RegisterAccountFailure('The password provided is too weak.'));
} else if (e.code == 'email-already-in-use') {
emit(RegisterAccountFailure(
'The account already exists for that email.'));
} else {
emit(RegisterAccountFailure(e.toString()));
}
}
try {
CollectionReference users =
FirebaseFirestore.instance.collection('User');
print("Trying to add");
await users.add({
'username': event.username,
'email': event.email,
'password': event.password
});
print("User Created");
emit(RegisterAccountSuccess());
} catch (error) {
emit(RegisterAccountFailure(error.toString()));
}
},
);
}
}
我尝试调试了几个小时,但此时没有任何变化的迹象。在 firebase 开始在身份验证选项卡中显示此消息之前它正在工作。
==> 许多浏览器不再支持跨源重定向登录。更新您的应用程序以确保您的用户可以继续登录您的应用程序。
您的代码没有任何问题,这是一个 firebase 身份验证问题,我也遇到了同样的问题,所做的就是将 firebase_auth 和 firebase_core 更新到最新版本,然后重新运行应用程序,这解决了我的问题。
参考:[https://github.com/firebase/flutterfire/issues/13077]