Flutter Phone authentication error original example

若如初见. 提交于 2019-12-10 19:56:25

问题


Dears,

I am developing this example (the original) of phone authentication: https://github.com/flutter/plugins/tree/master/packages/firebase_auth/example

Of course, I added the .json and correct dependencies (I think, because other complements of firebase works fine).

But, I get this part of code:

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';
  }

I have theses errors:

  • Undefined AuthCredential
  • Undefined name GoogleAuthProvider
  • The method signInWithCredential is not defined for class FirebaseAuth

Can you help me please? I don't understand these error if it is the original example.

Thanks!!


回答1:


It looks like that sample is outdated , you can omit AuthCredential and GoogleAuthProvider.

    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';
      } 


来源:https://stackoverflow.com/questions/53730531/flutter-phone-authentication-error-original-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!