Flutter Phone身份验证错误原始示例

时间:2018-12-11 18:47:12

标签: firebase authentication firebase-authentication flutter

亲爱的

我正在开发电话认证的此示例(原始示例): https://github.com/flutter/plugins/tree/master/packages/firebase_auth/example

当然,我添加了.json和正确的依赖项(我认为,因为firebase的其他补充版本工作正常)。

但是,我得到了这段代码:

Future<String> _testSignInWithGoogle() async {
    final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
    final GoogleSignInAuthentication googleAuth =
    await googleUser.authentication;
    final AuthCredential credential = GoogleAuthProvider.getCredential(
      accessToken: googleAuth.accessToken,
      idToken: googleAuth.idToken,
    );
    final FirebaseUser user = await _auth.signInWithCredential(credential);
    assert(user.email != null);
    assert(user.displayName != null);
    assert(!user.isAnonymous);
    assert(await user.getIdToken() != null);

    final FirebaseUser currentUser = await _auth.currentUser();
    assert(user.uid == currentUser.uid);

    return 'signInWithGoogle succeeded: $user';
  }

我有这些错误:

  • 未定义的AuthCredential
  • 未定义名称GoogleAuthProvider
  • 未为类FirebaseAuth定义方法signInWithCredential

能帮我吗?如果是原始示例,我不理解这些错误。

谢谢!

1 个答案:

答案 0 :(得分:3)

该示例似乎已过时,您可以省略AuthCredentialGoogleAuthProvider

    Future<String> _testSignInWithGoogle() async {
        final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
        final GoogleSignInAuthentication googleAuth =
        await googleUser.authentication;

        final FirebaseUser user =
            await FirebaseAuth.instance.signInWithGoogle(
          accessToken: googleAuth.accessToken,
          idToken: googleAuth.idToken,
        );

        assert(user.email != null);
        assert(user.displayName != null);
        assert(!user.isAnonymous);
        assert(await user.getIdToken() != null);

        final FirebaseUser currentUser = await _auth.currentUser();
        assert(user.uid == currentUser.uid);

        return 'signInWithGoogle succeeded: $user';
      }