I am trying to add google_sign_in functionality in my app and when i add details of my account it shows error in console and i am not redirected to another screen.
this is my code
class AuthMethods {
final FirebaseAuth auth = FirebaseAuth.instance;
getCurrentUser() async {
return auth.currentUser;
}
signInWithGoogle(BuildContext context) async {
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final GoogleSignIn googleSignIn = GoogleSignIn();
final GoogleSignInAccount? googleSignInAccount =
await googleSignIn.signIn();
final GoogleSignInAuthentication? googleSignInAuthentication =
await googleSignInAccount?.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
idToken: googleSignInAuthentication?.idToken,
accessToken: googleSignInAuthentication?.accessToken);
UserCredential result = await firebaseAuth.signInWithCredential(credential);
User? userDetails = result.user;
if (result != null) {
Map<String, dynamic> userInfoMap = {
"email": userDetails!.email,
"name": userDetails.displayName,
"imgUrl": userDetails.photoURL,
"id": userDetails.uid
};
await DatabaseMethods()
.addUser(userDetails.uid, userInfoMap)
.then((value) {
Navigator.push(
context, MaterialPageRoute(builder: (context) => const GoogleUserInfo()));
});
}
}
}
class DatabaseMethods {
Future addUser(String userId, Map<String, dynamic> userInfoMap) {
return FirebaseFirestore.instance
.collection("User")
.doc(userId)
.set(userInfoMap);
}
}
i have tried updating the outdated dependencies, also tried flutter clean and flutter pub get commands still issue persists.
This is primarily because you havent restarted your emulator or testing device.
1. In your terminal, `flutter clean`
2. Go to your `pubspec.yaml`, and update all the dependencies to the latest version by `pub get` then `pub upgrade`.
3. If in VS Code, restart your emulator and VS code completely.
4. If in Android Studio, go to File> Invalidate Caches> Check true to all the values you see in dialog and let it restart.
5. Try again and it will run.