//这是我的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:
//这是我的logcat
Error: The method 'signInWithPhoneNumber' isn't defined for the class 'FirebaseAuth'.
Try correcting the name to the name of an existing method, or defining a method named 'signInWithPhoneNumber'.
我正在flutter应用程序中实现电话号码登录。我安装了所有依赖项,还将google_services.json文件粘贴到了我的项目中。
答案 0 :(得分:3)
Flutter开发人员已将其用于电话身份验证的类和对象开发到Firebase中。因此,现在的方法是验证verifyId和smsId为:
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: verificationId,
smsCode: smsCode,
);
FirebaseAuth _auth = FirebaseAuth.instance;
final FirebaseUser user =
await _auth.signInWithCredential(credential).then((user) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DashboardPage(uid: user.user.uid)),
);
}).catchError((e) {
print(e);
});
答案 1 :(得分:0)
遇到同样的问题。我相信它已被替换:
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: _verificationId,
smsCode: _smsController.text,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);