google_sign_in_dartio 0.0.4+1
google_sign_in_dartio: ^0.0.4+1 copied to clipboard
Flutter package for Google Sign-In, a secure authentication system for signing in with a Google account on Flutter platforms that support 'dart:io'.
google_sign_in_dartio #
A Flutter package that implements Google Sign In in pure Dart. This package
is compatible with google_sign_in plugin and works on all platforms Flutter supports.
Getting Started #
Install and initialization #
- Depend on it
dependencies: google_sign_in: ^4.1.4 google_sign_in_dartio: ^0.0.1 - Run
flutter pub get - Import
import 'package:google_sign_in/google_sign_in.dart'; import 'package:google_sign_in_dartio/google_sign_in_dartio.dart'; - Register the package
Note: You might want toimport 'package:flutter/material.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:google_sign_in_dartio/google_sign_in_dartio.dart'; void main() { if (isDesktop) { GoogleSignInPlatform.register(clientId: <clientId>); } runApp(MyApp()); }awaitfor theregistermethod to finish before calling anyGoogleSignInmethods when your app starts.
Usage #
You can use the normal GoogleSignIn methods.
final GoogleSignInAccount account = await GoogleSignIn().signIn();
Obtain a Client ID for your Desktop app #
- Go to the Google Cloud Platform console and select you project
- Go to
APIs & Service->Credentials - Create new credentials for your app by selecting
CREATE CREDENTIALSand thenOAuth client ID - Select
OtherasApplication type, give it a name (eg. macOS) and then clickCreate
Provide a code exchange endpoint #
The user accessToken expires after about one hour, after witch you need to ask the user to login again. If you want to
keep the user logged in, you need to deploy a oAuth code exchange endpoint. Once you have your endpoint you can register
the package like this.
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:google_sign_in_dartio/google_sign_in_dartio.dart';
void main() {
if (isDesktop) {
GoogleSignInPlatform.register(
clientId: <clientId>,
exchangeEndpoint: <endpoint>,
);
}
runApp(MyApp());
}
See instruction on how to deploy a code exchange endpoint.