Skip to content

Commit 49af5dc

Browse files
committed
[gis_web] renderButton now accepts any js-interop target.
1 parent 74d64cd commit 49af5dc

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

packages/google_identity_services_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.0+1
2+
3+
* Relaxes the `renderButton` API so any JS-Interop Object can be its `target`.
4+
15
## 0.2.0
26

37
* Adds `renderButton` API to `id.dart`.

packages/google_identity_services_web/example/integration_test/js_interop_id_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:google_identity_services_web/id.dart';
99
import 'package:integration_test/integration_test.dart';
1010
import 'package:js/js.dart';
1111

12+
import 'src/dom.dart';
1213
import 'utils.dart' as utils;
1314

1415
void main() async {
@@ -19,6 +20,17 @@ void main() async {
1920
await utils.installGisMock();
2021
});
2122

23+
group('renderButton', () {
24+
testWidgets('supports a js-interop target from any library', (_) async {
25+
final DomElement target = createDomElement('div');
26+
27+
id.renderButton(target);
28+
29+
final DomElement? button = target.querySelector('button');
30+
expect(button, isNotNull);
31+
});
32+
});
33+
2234
group('prompt', () {
2335
testWidgets('supports a moment notification callback', (_) async {
2436
id.initialize(IdConfiguration(client_id: 'testing_1-2-3'));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: public_member_api_docs
6+
7+
import 'package:js/js.dart';
8+
import 'package:js/js_util.dart' as js_util;
9+
10+
@JS()
11+
@staticInterop
12+
class DomDocument {}
13+
extension DomDocumentExtension on DomDocument {
14+
DomElement createElement(String name, [Object? options]) =>
15+
js_util.callMethod(this, 'createElement',
16+
<Object>[name, if (options != null) options]) as DomElement;
17+
}
18+
19+
@JS()
20+
@staticInterop
21+
class DomElement {}
22+
23+
extension DomElementExtension on DomElement {
24+
external DomElement? querySelector(String selector);
25+
}
26+
27+
@JS('document')
28+
external DomDocument get domDocument;
29+
30+
DomElement createDomElement(String tag) => domDocument.createElement(tag);

packages/google_identity_services_web/example/web/mock-gis.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class Id {
3333
initialize(config) {
3434
this.config = config;
3535
}
36+
renderButton(target, config) {
37+
// Simulate rendering a button.
38+
target.replaceChildren();
39+
target.dataset.buttonConfig = config;
40+
let button = document.createElement('button');
41+
target.append(button);
42+
}
3643
prompt(momentListener) {
3744
callAsync(() => {
3845
if (this.mockCredentialResponse) {

packages/google_identity_services_web/lib/src/js_interop/google_accounts_id.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ library google_accounts_id;
1414

1515
import 'package:js/js.dart';
1616

17-
import 'dom.dart';
1817
import 'shared.dart';
1918

2019
/// Binding to the `google.accounts.id` JS global.
@@ -93,7 +92,7 @@ extension GoogleAccountsIdExtension on GoogleAccountsId {
9392
/// Method: google.accounts.id.renderButton
9493
/// https://developers.google.com/identity/gsi/web/reference/js-reference#google.accounts.id.renderButton
9594
external void renderButton(
96-
DomHtmlElement parent, [
95+
Object parent, [
9796
GsiButtonConfiguration options,
9897
]);
9998

packages/google_identity_services_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_identity_services_web
22
description: A Dart JS-interop layer for Google Identity Services. Google's new sign-in SDK for Web that supports multiple types of credentials.
33
repository: https://github.com/flutter/packages/tree/main/packages/google_identity_services_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_identiy_services_web%22
5-
version: 0.2.0
5+
version: 0.2.0+1
66

77
environment:
88
sdk: ">=2.17.0 <3.0.0"

0 commit comments

Comments
 (0)