-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[gsi_web] Adds Sign In button. #3636
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
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b8a2466
[gsi_web] Adds Sign In Button.
ditman 8d31b42
[gsi_web] Fix CHANGELOG and pubspec.
ditman cceaeab
Remove dead code.
ditman 28e1a06
Format URLs in DartDoc
ditman d15236d
Properly document the initialized Future.
ditman b94eb08
Some more PR tweaks.
ditman d631710
dart format .
ditman c5f3015
Format pubspec as expected.
ditman d4a3afd
Add console lang to README codeblock
ditman 4f87ee2
Add console.warn.
ditman a6ccaad
Fix init. Warn users that signIn is discouraged on the web.
ditman 628dfad
Make plugin instance final.
ditman da32e8f
Update README
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
207 changes: 207 additions & 0 deletions
207
..._in/google_sign_in_web/example/integration_test/flexible_size_html_element_view_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:async'; | ||
| import 'dart:ui' as ui; | ||
|
|
||
| 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'; | ||
|
|
||
| /// Used to keep track of the number of HtmlElementView factories the test has registered. | ||
| int widgetFactoryNumber = 0; | ||
|
|
||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| group('FlexHtmlElementView', () { | ||
| tearDown(() { | ||
| widgetFactoryNumber++; | ||
| }); | ||
|
|
||
| testWidgets('empty case, calls onPlatformViewCreated', | ||
| (WidgetTester tester) async { | ||
| final Completer<int> viewCreatedCompleter = Completer<int>(); | ||
|
|
||
| await pumpResizableWidget(tester, onPlatformViewCreated: (int id) { | ||
| viewCreatedCompleter.complete(id); | ||
| }); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| await expectLater(viewCreatedCompleter.future, completes); | ||
| }); | ||
|
|
||
| testWidgets('empty case, renders with initial size', | ||
| (WidgetTester tester) async { | ||
| const Size initialSize = Size(160, 100); | ||
|
|
||
| final Element element = await pumpResizableWidget( | ||
| tester, | ||
| initialSize: initialSize, | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // Expect that the element matches the initialSize. | ||
| expect(element.size!.width, initialSize.width); | ||
| expect(element.size!.height, initialSize.height); | ||
| }); | ||
|
|
||
| testWidgets('initialSize null, adopts size of injected element', | ||
| (WidgetTester tester) async { | ||
| const Size childSize = Size(300, 40); | ||
|
|
||
| final DomHtmlElement resizable = document.createElement('div'); | ||
| resize(resizable, childSize); | ||
|
|
||
| final Element element = await pumpResizableWidget( | ||
| tester, | ||
| onPlatformViewCreated: injectElement(resizable), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // Expect that the element matches the initialSize. | ||
| expect(element.size!.width, childSize.width); | ||
| expect(element.size!.height, childSize.height); | ||
| }); | ||
|
|
||
| testWidgets('with initialSize, adopts size of injected element', | ||
| (WidgetTester tester) async { | ||
| const Size initialSize = Size(160, 100); | ||
| const Size newSize = Size(300, 40); | ||
|
|
||
| final DomHtmlElement resizable = document.createElement('div'); | ||
| resize(resizable, newSize); | ||
|
|
||
| final Element element = await pumpResizableWidget( | ||
| tester, | ||
| initialSize: initialSize, | ||
| onPlatformViewCreated: injectElement(resizable), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // Expect that the element matches the initialSize. | ||
| expect(element.size!.width, newSize.width); | ||
| expect(element.size!.height, newSize.height); | ||
| }); | ||
|
|
||
| testWidgets('with injected element that resizes, follows resizes', | ||
| (WidgetTester tester) async { | ||
| const Size initialSize = Size(160, 100); | ||
| final Size expandedSize = initialSize * 2; | ||
| final Size contractedSize = initialSize / 2; | ||
|
|
||
| final DomHtmlElement resizable = document.createElement('div') | ||
| ..setAttribute( | ||
| 'style', 'width: 100%; height: 100%; background: #fabada;'); | ||
|
|
||
| final Element element = await pumpResizableWidget( | ||
| tester, | ||
| initialSize: initialSize, | ||
| onPlatformViewCreated: injectElement(resizable), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| // Expect that the element matches the initialSize, because the | ||
| // resizable is defined as width:100%, height:100%. | ||
| expect(element.size!.width, initialSize.width); | ||
| expect(element.size!.height, initialSize.height); | ||
|
|
||
| // Expands | ||
| resize(resizable, expandedSize); | ||
|
|
||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(element.size!.width, expandedSize.width); | ||
| expect(element.size!.height, expandedSize.height); | ||
|
|
||
| // Contracts | ||
| resize(resizable, contractedSize); | ||
|
|
||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(element.size!.width, contractedSize.width); | ||
| expect(element.size!.height, contractedSize.height); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /// Injects a ResizableFromJs widget into the `tester`. | ||
| Future<Element> pumpResizableWidget( | ||
| WidgetTester tester, { | ||
| void Function(int)? onPlatformViewCreated, | ||
| Size? initialSize, | ||
| }) async { | ||
| await tester.pumpWidget(ResizableFromJs( | ||
| instanceId: widgetFactoryNumber, | ||
| onPlatformViewCreated: onPlatformViewCreated, | ||
| initialSize: initialSize, | ||
| )); | ||
| // Needed for JS to have time to kick-off. | ||
| await tester.pump(); | ||
|
|
||
| // Return the element we just pumped | ||
| final Iterable<Element> elements = | ||
| find.byKey(Key('resizable_from_js_$widgetFactoryNumber')).evaluate(); | ||
| expect(elements, hasLength(1)); | ||
| return elements.first; | ||
| } | ||
|
|
||
| class ResizableFromJs extends StatelessWidget { | ||
| ResizableFromJs({ | ||
| required this.instanceId, | ||
| this.onPlatformViewCreated, | ||
| this.initialSize, | ||
| super.key, | ||
| }) { | ||
| // ignore: avoid_dynamic_calls, undefined_prefixed_name | ||
| ui.platformViewRegistry.registerViewFactory( | ||
| 'resizable_from_js_$instanceId', | ||
| (int viewId) { | ||
| final DomHtmlElement element = document.createElement('div'); | ||
| element.setAttribute('style', | ||
| 'width: 100%; height: 100%; overflow: hidden; background: red;'); | ||
| element.id = 'test_element_$viewId'; | ||
| return element; | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| final int instanceId; | ||
| final void Function(int)? onPlatformViewCreated; | ||
| final Size? initialSize; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| home: Scaffold( | ||
| body: Center( | ||
| child: FlexHtmlElementView( | ||
| viewType: 'resizable_from_js_$instanceId', | ||
| key: Key('resizable_from_js_$instanceId'), | ||
| onPlatformViewCreated: onPlatformViewCreated, | ||
| initialSize: initialSize ?? const Size(640, 480), | ||
| ), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Resizes `resizable` to `size`. | ||
| void resize(DomHtmlElement 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) { | ||
| return (int viewId) { | ||
| final DomHtmlElement root = | ||
| document.querySelector('#test_element_$viewId')!; | ||
| root.appendChild(element); | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.