gpt4 book ai didi

flutter - 错误:未为类 'signInWithPhoneNumber'定义方法 'FirebaseAuth'

转载 作者:行者123 更新时间:2023-12-03 03:37:10 25 4
gpt4 key购买 nike

我找不到带firebaseAuth类的signInWithPhoneNumber方法

//main.dart代码

signIn() {

FirebaseAuth.instance
.signInWithPhoneNumber(verificationId: verificationId, smsCode:smsCode)
.then((user) {
Navigator.of(context).pushReplacementNamed('/homepage');
}).catchError((e) {
print(e);
});
}

//pubspec.yaml代码
  dependencies:
flutter:
sdk: flutter



# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.

cupertino_icons: ^0.1.2

firebase_auth:

最佳答案

signWithPhoneNumber中没有FirebaseAuth的方法

使用signInWithCredential方法将代码发送给用户后,用电话号码签名

例如:如果传递的代码为true,则此方法将返回 firebaseUser ,否则返回 null

Future<FirebaseUser> getUserFromCodePhone(
String code, String verificationID) async {
FirebaseAuth mAuth = FirebaseAuth.instance;

AuthCredential phoneAuthCredential = PhoneAuthProvider.getCredential(
verificationId: verificationID, smsCode: code);
try {
AuthResult result = await mAuth.signInWithCredential(phoneAuthCredential);

FirebaseUser currentUser = await mAuth.currentUser();
if (currentUser != null && result.user.uid == currentUser.uid) {
return currentUser;
} else {
return null;
}
} on PlatformException catch (_) {}

return null;
}

关于flutter - 错误:未为类 'signInWithPhoneNumber'定义方法 'FirebaseAuth',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60081875/

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