问题
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