我找不到带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;
}