I am simply trying to use sign in with Google in Firebase.
Error: "Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)"
I have it enabled and my SHA1 is added in the settings. I have all the required dependencies and applies as well as the .json file that is needed.
Here is my main.dart
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
FirebaseAuth _auth = FirebaseAuth.instance;
User _user;
GoogleSignIn _googleSignIn = new GoogleSignIn();
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text("google Authentication"),
),
body: isSignIn
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundImage: NetworkImage(_user.photoURL),
),
Text(_user.displayName),
OutlineButton(
onPressed: () {
gooleSignout();
},
child: Text("Logout"),
)
],
),
)
: Center(
child: OutlineButton(
onPressed: () {
handleSignIn();
},
child: Text("Sign in with Google"),
),
)),
);
}
bool isSignIn = false;
Future<void> handleSignIn() async {
GoogleSignInAccount googleSignInAccount = await _googleSignIn.signIn();
GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
AuthCredential credential = GoogleAuthProvider.credential(
idToken: googleSignInAuthentication.idToken,
accessToken: googleSignInAuthentication.accessToken);
var result = (await _auth.signInWithCredential(credential));
_user = result.user;
setState(() {
isSignIn = true;
});
}
Future<void> gooleSignout() async {
await _auth.signOut().then((onValue) {
_googleSignIn.signOut();
setState(() {
isSignIn = true;
});
});
}
}
I am not sure why it is behaving like this and giving me an error.
Not sure why I have to add more text to compensate for the amount of code. Pretty much explained everything.