gpt4 book ai didi

firebase - 方法 'getCredential' 没有为类型 'PhoneAuthProvider' 定义

转载 作者:行者123 更新时间:2023-12-05 04:54:05 25 4
gpt4 key购买 nike

据我所知,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 上看到关于这个错误的各种问题,但我还找不到解决方法

最佳答案

这就是我在 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');
}
}

关于firebase - 方法 'getCredential' 没有为类型 'PhoneAuthProvider' 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65887150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com