Google One Tap 登录
Google One Tap 登录 (Android)
一个用于 Google One Tap 登录 的 Flutter 插件
入门
要访问 Google 登录,您需要确保 注册您的应用程序。
-
添加到您的 pubspec.yaml
dependencies: google_one_tap_sign_in: [any] -
添加 Google 服务
classpath 'com.google.gms:google-services:[x.x.x]' -
导入插件
import 'package:google_one_tap_sign_in/google_one_tap_sign_in.dart'; -
处理简单方法
// Your Web Client Id final String _webClientId = "[XXXXXXXXXXX]"; void _onSignIn() async { var data = await GoogleOneTapSignIn.startSignIn(webClientId: _webClientId); if (data != null) { // Whatever you do with [SignInResult] data print("Id Token : ${data.idToken ?? "-"}"); print("ID : ${data.id ?? "-"}"); } } -
使用条件方法处理
// Your Web Client Id final String _webClientId = "[XXXXXXXXXXX]"; void _onSignInWithHandle() async { var result = await GoogleOneTapSignIn.handleSignIn(webClientId: _webClientId); if (result.isTemporaryBlock) { // TODO: Tell your users about this status print("Temporary BLOCK"); } if (result.isCanceled) { // TODO: Tell your users about this status print("Canceled"); } if (result.isFail) { // TODO: Tell your users about this status } if (result.isOk) { // TODO: Whatever you do with [SignInResult] data print("OK"); print("Id Token : ${result.data?.idToken ?? "-"}"); print("Email : ${result.data?.username ?? "-"}"); } }
示例
在 Google One Tap 登录 中找到示例接线