未为类 FirebaseAuth 定义 Flutter firebase signInWithPhoneNumber

Vis*_*ali 8 flutter

//这是我的main.dart代码

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

//这是我的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:
Run Code Online (Sandbox Code Playgroud)

//这是我的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'.
Run Code Online (Sandbox Code Playgroud)

我正在我的 flutter 应用程序中实现电话号码登录。我安装了所有依赖项,并在我的项目中粘贴了 google_services.json 文件。

小智 6

遇到了同样的问题。我相信它已被替换:

final AuthCredential credential = PhoneAuthProvider.getCredential(
  verificationId: _verificationId,
  smsCode: _smsController.text,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
Run Code Online (Sandbox Code Playgroud)

https://github.com/flutter/plugins/blob/master/packages/firebase_auth/example/lib/signin_page.dart#L423-L427