A Flutter plugin for Google Sign In.
Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!
Android | iOS | Web | |
---|---|---|---|
Support | SDK 16+ | iOS 9+ | Any |
To access Google Sign-In, you'll need to make sure to register your application.
You don‘t need to include the google-services.json file in your app unless you are using Google services that require it. You do need to enable the OAuth APIs that you want, using the Google Cloud Platform API manager. For example, if you want to mimic the behavior of the Google Sign-In sample app, you’ll need to enable the Google People API.
Make sure you've filled out all required fields in the console for OAuth consent screen. Otherwise, you may encounter APIException
errors.
This plugin requires iOS 9.0 or higher.
GoogleService-Info.plist
.GoogleService-Info.plist
into the [my_project]/ios/Runner
directory.Runner
directory and select Add Files to "Runner"
.GoogleService-Info.plist
from the file manager.Runner
target.CFBundleURLTypes
attributes below into the [my_project]/ios/Runner/Info.plist
file.<!-- Put me in the [my_project]/ios/Runner/Info.plist file --> <!-- Google Sign-in Section --> <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <!-- TODO Replace this value: --> <!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID --> <string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string> </array> </dict> </array> <!-- End of the Google Sign-in Section -->
Note that according to https://developer.apple.com/sign-in-with-apple/get-started, starting June 30, 2020, apps that use login services must also offer a “Sign in with Apple” option when submitting to the Apple App Store.
Consider also using an Apple sign in plugin from pub.dev.
The Flutter Favorite sign_in_with_apple plugin could be an option.
For web integration details, see the google_sign_in_web
package.
To use this plugin, follow the plugin installation instructions.
Add the following import to your Dart code:
import 'package:google_sign_in/google_sign_in.dart';
Initialize GoogleSignIn with the scopes you want:
GoogleSignIn _googleSignIn = GoogleSignIn( scopes: [ 'email', 'https://www.googleapis.com/auth/contacts.readonly', ], );
Full list of available scopes.
You can now use the GoogleSignIn
class to authenticate in your Dart code, e.g.
Future<void> _handleSignIn() async { try { await _googleSignIn.signIn(); } catch (error) { print(error); } }
Find the example wiring in the Google sign-in example application.