Skip to content

Commit

Permalink
[extension_google_sign_in_as_googleapis_auth] Adopt code excerpts in … (
Browse files Browse the repository at this point in the history
#5496)

�README

Updates the README to use a compiled excerpt source for its example of using google_sign_in plugin with the `googleapis` package.

Part of [flutter/flutter#102679](flutter/flutter#102679)
  • Loading branch information
mike-v2 committed Dec 15, 2023
1 parent 120e6f4 commit eeb2c66
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 2.0.12

* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.
* Updates README to improve example of using google_sign_in plugin with the `googleapis` package.

## 2.0.11

Expand Down
16 changes: 13 additions & 3 deletions packages/extension_google_sign_in_as_googleapis_auth/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# extension_google_sign_in_as_googleapis_auth

A bridge package between Flutter's [`google_sign_in` plugin](https://pub.dev/packages/google_sign_in) and Dart's [`googleapis` package](https://pub.dev/packages/googleapis), that is able to create [`googleapis_auth`-like `AuthClient` instances](https://pub.dev/documentation/googleapis_auth/latest/googleapis_auth.auth/AuthClient-class.html) directly from the `GoogleSignIn` plugin.
A bridge package between Flutter's [`google_sign_in` plugin](https://pub.dev/packages/google_sign_in) and Dart's [`googleapis` package](https://pub.dev/packages/googleapis), that is able to create [`googleapis_auth`-like `AuthClient` instances](https://pub.dev/documentation/googleapis_auth/latest/googleapis_auth/AuthClient-class.html) directly from the `GoogleSignIn` plugin.

## Usage

This package is implemented as an [extension method](https://dart.dev/guides/language/extension-methods) on top of the `GoogleSignIn` plugin.

In order to use it, you need to add a `dependency` to your `pubspec.yaml`. Then, wherever you're importing `package:google_sign_in/google_sign_in.dart`, add the following:

<?code-excerpt "example/lib/main.dart (Import)"?>
```dart
import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';
```
Expand All @@ -16,9 +17,18 @@ From that moment on, your `GoogleSignIn` instance will have an additional `Futur

That object can then be used to create instances of `googleapis` API clients:

<?code-excerpt "example/lib/main.dart (CreateAPIClient)"?>
```dart
final peopleApi = PeopleApi((await _googleSignIn.authenticatedClient())!);
final response = await peopleApi.people.connections.list(
// Retrieve an [auth.AuthClient] from the current [GoogleSignIn] instance.
final auth.AuthClient? client = await _googleSignIn.authenticatedClient();
assert(client != null, 'Authenticated client missing!');
// Prepare a People Service authenticated client.
final PeopleServiceApi peopleApi = PeopleServiceApi(client!);
// Retrieve a list of the `names` of my `connections`
final ListConnectionsResponse response =
await peopleApi.people.connections.list(
'people/me',
personFields: 'names',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import 'dart:async';

// #docregion Import
import 'package:extension_google_sign_in_as_googleapis_auth/extension_google_sign_in_as_googleapis_auth.dart';
// #enddocregion Import
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:googleapis/people/v1.dart';
Expand Down Expand Up @@ -58,6 +60,7 @@ class SignInDemoState extends State<SignInDemo> {
_contactText = 'Loading contact info...';
});

// #docregion CreateAPIClient
// Retrieve an [auth.AuthClient] from the current [GoogleSignIn] instance.
final auth.AuthClient? client = await _googleSignIn.authenticatedClient();

Expand All @@ -71,6 +74,7 @@ class SignInDemoState extends State<SignInDemo> {
'people/me',
personFields: 'names',
);
// #enddocregion CreateAPIClient

final String? firstNamedContactName =
_pickFirstNamedContact(response.connections);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: extension_google_sign_in_as_googleapis_auth
description: A bridge package between google_sign_in and googleapis_auth, to create Authenticated Clients from google_sign_in user credentials.
repository: https://github.com/flutter/packages/tree/main/packages/extension_google_sign_in_as_googleapis_auth
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+extension_google_sign_in_as_googleapis_auth%22
version: 2.0.11
version: 2.0.12

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
1 change: 0 additions & 1 deletion script/configs/temp_exclude_excerpt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# TODO(stuartmorgan): Remove everything from this list. See
# https://github.com/flutter/flutter/issues/102679
- espresso
- extension_google_sign_in_as_googleapis_auth
- go_router_builder
- image_picker_for_web
- in_app_purchase/in_app_purchase
Expand Down

0 comments on commit eeb2c66

Please sign in to comment.