I want to use google signin in my flutter app but it keeps throwing error
PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)
I am using google singin through a button
class LoginPage extends StatelessWidget {
const LoginPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final GoogleSignIn _google_sign_in = Provider.of<GoogleSignIn>(context, listen: false);
final FirebaseAuth _auth = Provider.of<FirebaseAuth>(context, listen: false);
return Scaffold(
appBar: AppBar(
title: Text('Login'),
),
body: SingleChildScrollView(
child: Container(
width: MediaQuery.of(context).size.width,
child: GestureDetector(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 15),
child: Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.40,
),
Container(
width: 250,
child: ElevatedButton(
onPressed: () async {
try{
GoogleSignInAccount? googleCreds = await _google_sign_in.signIn();
if(googleCreds == null){
print('creds null');
}else{
final GoogleSignInAuthentication googleAuth = await googleCreds.authentication;
final OAuthCredential credentials = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
await _auth.signInWithCredential(credentials);
}
}catch(e){
print(e.toString());
}
},
child: Text('Google'),
),
),
Container(
width: 250,
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pushNamed('/EmailLogin');
},
child: Text('Email'),
),
),
],
),
),
),
),
),
);
}
}
my build gradle:
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
my app level build gradle:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 30
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.minor"
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:28.4.0')
}
I gave SHA1 and SHA256 to my firebase project and also have downloaded google-services.json.