据我所知,在flutter firebase身份验证中有许多不推荐使用的方法。
这是我的代码;
FlatButton(
child: Text("Confirm"),
textColor: Colors.white,
color: Colors.blue,
onPressed: () async {
FirebaseAuth _auth = FirebaseAuth.instance; // I didn't use it here. I did for you to see
final code = _codeController.text.trim();
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: verificationId, smsCode: code);
UserCredential result =
await _auth.signInWithCredential(credential);
User user = result.user;
if (user != null) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
HomeScreen(user: user)));
} else {
print("Error");
}
},
)
我尝试进行电话身份验证,但getCredential出错。我查看了firebase文档。它说PhoneAuthProvider已弃用,我应该将PhoneAuthCredential与getCredential一起使用。我用过它,但它不起作用。我在stackoverflow上看到了关于这个错误的各种问题,但我还没有找到解决方法
发布于 2021-01-25 17:25:54
这就是我在firebase_auth: ^0.18.0+1
上的应用程序中实现它的方式
@override
Future<void> signInWithSmsCode(String smsCode) async {
final AuthCredential authCredential = PhoneAuthProvider.credential(
smsCode: smsCode,
verificationId: _verificationCode,
);
try {
await auth.signInWithCredential(authCredential);
} on PlatformException catch (e) {
throw _firebaseErrorFactory.getException(e.code);
} on FirebaseAuthException {
throw _firebaseErrorFactory
.getException('ERROR_INVALID_VERIFICATION_CODE');
}
}
https://stackoverflow.com/questions/65887150
复制