Flutter实现google登陆(gmail)-爱代码爱编程
环境介绍
系统:Windows 10
IDE:Android Studio 3.5.2
Flutter:1.22.2
Dart:2.8.4
Gradle:5.6.2
插件
平台
Android
- 前往Firebase创建项目
- 侧边栏进入build -> Authentication -> Sign-in method,开启Google项
- 侧边栏进入 Project Overview ,创建APP
- 进入APP设置,填写基本信息
- 使用keytool创建keystore,并获取SHA-1、SHA-256,并填写到对应APP信息中
- 下载google-services.json放入android/app/
- 配置OAuth同意屏
- 配置android/build.gradle
buildscript{ ... repositories{ maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } } dependencies{ ... classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.3' } } ... allprojects{ repositories{ maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } } }
- 配置android/app/build.gradle
dependencies{ implementation 'com.google.firebase:firebase-analytics:17.2.2' } apply plugin: 'com.google.gms.google-services'
- 编写代码
// 要求的 google token scope final GoogleSignIn _googleSignIn = GoogleSignIn( scopes: <String>[ 'email', 'profile', ], ); // 谷歌登陆 Future _loginForGoogle(BuildContext context) async { await _googleSignIn.signOut(); GoogleSignInAccount _currentUser = await _googleSignIn.signIn(); GoogleSignInAuthentication gSA = await _currentUser.authentication; var id = _currentUser.id; // 需要发送给后端的accessToken String accessToken = gSA.accessToken; // ...继续操作 }
IOS
待补充
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/codecat_yi/article/details/111114518