我正在使用 FirebaseAuth 电话验证,我的问题是我正在使用 bloc 模式,所以我希望 FirebaseAuth 电话验证方法向 Bloc 返回一些变量,以指示用户是否已经存在以导航到电话验证屏幕.
这是我的手机验证方法,注意这个函数在另一个类中,不在Bloc中:
static sendPhoneVerificationMessage(String phone) async {
AuthCredential credential;
final PhoneVerificationCompleted verificationCompleted = (AuthCredential user){
print('Inside _sendCodeToPhoneNumber: signInWithPhoneNumber auto succeeded: '+user.toString());
};
final PhoneVerificationFailed verificationFailed = (AuthException authException){
print('Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}');
};
final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
verificationCode = verificationId;
print("code sent to " + phone);
};
final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) {
verificationCode = verificationId;
print("time out");
};
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: phone,
timeout: const Duration(seconds: 120),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
}
这是 bloc 中调用前一个函数的函数
static sendPhoneVerificationMessage(String phone) async {
String formattedPhone = "+2" + phone;
await AuthAPI.sendPhoneVerificationMessage(formattedPhone);
}
我想要的是根据 sendPhoneVerificationMessage 函数的返回执行一些操作