This is a sample project showing how to use Dart and Flutter to connect to Google services. This particular project connects to Google Drive and creates a file. Other services would have similar authentication and authorization requirements with differences in how the service is accessed.
You will need to set up API access on the Google Developer Console.
- Create a new project from the "Select a project" dropdown.
- Be sure project is selected in dropdown after it is created.
- Select "Library" from the left menu.
- Search for "Drive". Select "Google Drive API" from the results.
- Click the "Enable" button.
- Click "OAuth consent screen" from the left menu.
- Choose "External" for User Type.
- Fill in the required fields (App Name, email addresses).
- This information will appear on the consent screen.
- Click "Save and Continue" at the bottom of the screen.
- The next screen will have you choose Scopes.
- Click "Add or Remove Scopes" button.
- Filter for "drive.file". Select the checkbox for that scope.
- Click the "Update" button.
- Click "Save and Continue".
- The next screen will have you add a test user.
- This is for testing only. Once (if?) you have "published" your app this is unnecessary. Since this is a test app, this probably won't get published.
- Add the user you will use on your emulator.
- Select "Credentials" from the left menu.
- Click "Create Credentials" at the top of the page.
- Choose the "OAuth client ID" option.
- Choose Android.
- Choose a name (or leave it the default).
- Package name must match the package name in the
AndroidManifest.xml
file. If you clone this repository, you will need to change it as the package currently set there has already been claimed. - To get the SHA-1 fingerprint,
cd
into theandroid
directory and execute this Gradle task:./gradlew signingReport
. Copy and past the appropriate entry. - Click into your new credentials and copy the client id you just created. It will look something like
123456789453-lkajhsdlf89ah8fh9as98dhfb.apps.googleusercontent.com
.
Now to setup the project:
- Paste your Client ID in the file
lib/domain/secret.dart
. It also needs to go in theAndroidManifest.xml
file in a sort of reversed notation. If the above example was your client id, this is how it will look:com.googleusercontent.apps.123456789453-lkajhsdlf89ah8fh9as98dhfb
. - At this point, you should be able to run the code in an Android emulator.
I was unable to test this in an iOS emulator, but in theory it should work if you setup a Client ID for iOS in the Google Developer Console.