Skip to content

[google_sign_in_web] Migrate to pkg:web. #5612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/google_sign_in/google_sign_in_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.12.3

* Migrates to `package:web`.
* Updates minimum supported SDK version to Flutter 3.16.0/Dart 3.2.0.

## 0.12.2+1

* Re-publishes `0.12.2` with a small fix to the CodeClient initialization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:google_sign_in_web/src/flexible_size_html_element_view.dart';
import 'package:integration_test/integration_test.dart';

import 'src/dom.dart';
import 'package:web/web.dart' as web;

/// Used to keep track of the number of HtmlElementView factories the test has registered.
int widgetFactoryNumber = 0;
Expand Down Expand Up @@ -54,7 +53,8 @@ void main() {
(WidgetTester tester) async {
const Size childSize = Size(300, 40);

final DomHtmlElement resizable = document.createElement('div');
final web.HTMLDivElement resizable =
web.document.createElement('div') as web.HTMLDivElement;
resize(resizable, childSize);

final Element element = await pumpResizableWidget(
Expand All @@ -73,7 +73,8 @@ void main() {
const Size initialSize = Size(160, 100);
const Size newSize = Size(300, 40);

final DomHtmlElement resizable = document.createElement('div');
final web.HTMLDivElement resizable =
web.document.createElement('div') as web.HTMLDivElement;
resize(resizable, newSize);

final Element element = await pumpResizableWidget(
Expand All @@ -94,7 +95,8 @@ void main() {
final Size expandedSize = initialSize * 2;
final Size contractedSize = initialSize / 2;

final DomHtmlElement resizable = document.createElement('div')
final web.HTMLDivElement resizable = web.document.createElement('div')
as web.HTMLDivElement
..setAttribute(
'style', 'width: 100%; height: 100%; background: #fabada;');

Expand Down Expand Up @@ -160,7 +162,8 @@ class ResizableFromJs extends StatelessWidget {
ui_web.platformViewRegistry.registerViewFactory(
'resizable_from_js_$instanceId',
(int viewId) {
final DomHtmlElement element = document.createElement('div');
final web.HTMLDivElement element =
web.document.createElement('div') as web.HTMLDivElement;
element.setAttribute('style',
'width: 100%; height: 100%; overflow: hidden; background: red;');
element.id = 'test_element_$viewId';
Expand Down Expand Up @@ -191,16 +194,16 @@ class ResizableFromJs extends StatelessWidget {
}

/// Resizes `resizable` to `size`.
void resize(DomHtmlElement resizable, Size size) {
void resize(web.HTMLElement resizable, Size size) {
resizable.setAttribute('style',
'width: ${size.width}px; height: ${size.height}px; background: #fabada');
}

/// Returns a function that can be used to inject `element` in `onPlatformViewCreated` callbacks.
void Function(int) injectElement(DomHtmlElement element) {
void Function(int) injectElement(web.HTMLElement element) {
return (int viewId) {
final DomHtmlElement root =
document.querySelector('#test_element_$viewId')!;
root.appendChild(element);
final web.Element? root =
web.document.querySelector('#test_element_$viewId');
root!.appendChild(element);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import 'package:google_sign_in_web/src/people.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart' as mockito;
import 'package:web/web.dart' as web;

import 'google_sign_in_web_test.mocks.dart';
import 'src/dom.dart';
import 'src/person.dart';

// Mock GisSdkClient so we can simulate any response from the JS side.
Expand All @@ -36,12 +36,12 @@ void main() {
expect(plugin.autoDetectedClientId, isNull);

// Add it to the test page now, and try again
final DomHtmlMetaElement meta =
document.createElement('meta') as DomHtmlMetaElement
final web.HTMLMetaElement meta =
web.document.createElement('meta') as web.HTMLMetaElement
..name = clientIdMetaName
..content = expectedClientId;

document.head.appendChild(meta);
web.document.head!.appendChild(meta);

final GoogleSignInPlugin another = GoogleSignInPlugin(
debugOverrideLoader: true,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:js/js_util.dart' as js_util;
import 'dart:js_interop';

/// Converts a [data] object into a JS Object of type `T`.
T jsifyAs<T>(Map<String, Object?> data) {
return js_util.jsify(data) as T;
return data.jsify() as T;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: google_sign_in_web_integration_tests
publish_to: none

environment:
sdk: ">=3.1.0 <4.0.0"
flutter: ">=3.13.0"
sdk: ">=3.2.0 <4.0.0"
flutter: ">=3.16.0"

dependencies:
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
google_identity_services_web: ^0.2.1
google_identity_services_web: ^0.3.0
google_sign_in_platform_interface: ^2.4.0
google_sign_in_web:
path: ../
Expand All @@ -21,8 +21,8 @@ dev_dependencies:
http: ">=0.13.0 <2.0.0"
integration_test:
sdk: flutter
js: ^0.6.3
mockito: 5.4.3
web: ">=0.3.0 <0.5.0"

flutter:
uses-material-design: true
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:html' as html;
import 'dart:js_interop';
import 'dart:ui_web' as ui_web;

import 'package:flutter/foundation.dart' show visibleForTesting, kDebugMode;
Expand All @@ -13,9 +13,9 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:google_identity_services_web/loader.dart' as loader;
import 'package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart';
import 'package:web/web.dart' as web;

import 'src/button_configuration.dart' show GSIButtonConfiguration;
import 'src/dom.dart';
import 'src/flexible_size_html_element_view.dart';
import 'src/gis_client.dart';

Expand Down Expand Up @@ -54,7 +54,7 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
}) : _gisSdkClient = debugOverrideGisSdkClient,
_userDataController = debugOverrideUserDataController ??
StreamController<GoogleSignInUserData?>.broadcast() {
autoDetectedClientId = html
autoDetectedClientId = web.document
.querySelector(clientIdMetaSelector)
?.getAttribute(clientIdAttributeName);

Expand Down Expand Up @@ -175,7 +175,7 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
ui_web.platformViewRegistry.registerViewFactory(
'gsi_login_button',
(int viewId) {
final DomElement element = createDomElement('div');
final web.Element element = web.document.createElement('div');
element.setAttribute('style',
'width: 100%; height: 100%; overflow: hidden; display: flex; flex-wrap: wrap; align-content: center; justify-content: center;');
element.id = 'sign_in_button_$viewId';
Expand All @@ -196,8 +196,8 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
return FlexHtmlElementView(
viewType: 'gsi_login_button',
onPlatformViewCreated: (int viewId) {
final DomElement? element =
domDocument.querySelector('#sign_in_button_$viewId');
final web.Element? element =
web.document.querySelector('#sign_in_button_$viewId');
assert(element != null,
'Cannot render GSI button. DOM is not ready!');
_gisClient.renderButton(element!, config);
Expand All @@ -219,10 +219,11 @@ class GoogleSignInPlugin extends GoogleSignInPlatform {
@override
Future<GoogleSignInUserData?> signIn() async {
if (kDebugMode) {
domConsole.warn(
web.console.warn(
"The `signIn` method is discouraged on the web because it can't reliably provide an `idToken`.\n"
'Use `signInSilently` and `renderButton` to authenticate your users instead.\n'
'Read more: https://pub.dev/packages/google_sign_in_web');
'Use `signInSilently` and `renderButton` to authenticate your users instead.\n'
'Read more: https://pub.dev/packages/google_sign_in_web'
.toJS);
}
await initialized;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// found in the LICENSE file.

import 'package:google_identity_services_web/id.dart' as id;
import 'package:js/js_util.dart' as js_util;

/// Converts user-facing `GisButtonConfiguration` into the JS-Interop `id.GsiButtonConfiguration`.
id.GsiButtonConfiguration? convertButtonConfiguration(
Expand All @@ -12,17 +11,16 @@ id.GsiButtonConfiguration? convertButtonConfiguration(
if (config == null) {
return null;
}
return js_util.jsify(<String, Object?>{
if (config.type != null) 'type': _idType[config.type],
if (config.theme != null) 'theme': _idTheme[config.theme],
if (config.size != null) 'size': _idSize[config.size],
if (config.text != null) 'text': _idText[config.text],
if (config.shape != null) 'shape': _idShape[config.shape],
if (config.logoAlignment != null)
'logo_alignment': _idLogoAlignment[config.logoAlignment],
if (config.minimumWidth != null) 'width': config.minimumWidth,
if (config.locale != null) 'locale': config.locale,
}) as id.GsiButtonConfiguration;
return id.GsiButtonConfiguration(
type: _idType[config.type],
theme: _idTheme[config.theme],
size: _idSize[config.size],
text: _idText[config.text],
shape: _idShape[config.shape],
logo_alignment: _idLogoAlignment[config.logoAlignment],
width: config.minimumWidth,
locale: config.locale,
);
}

/// A class to configure the Google Sign-In Button for web.
Expand Down
Loading