Skip to content

Commit b21dce5

Browse files
authored
[web] Updates package:web dependency to ^0.5.0. (flutter#5791)
This PR updates the packages that are using `package:web` to version `^0.5.0`. Ancilliary changes: * Bump `environment` to `flutter: ">=3.19.0"` and `sdk: ^3.3.0`. * Bump version to next `Y` * Clean-up code that was kept for compatibility with versions of `web: <0.5.0`. The main exception to this is `package:google_sign_in_web`, which depends on a version of `google_identity_services_web` that has a dependency on package:web that is `<0.5.0`, so that package needs to have a range until `google_identity_services_web` gets published with the new ^0.5.0 dependency. Co-Authored-By: David Iglesias<[email protected]>
1 parent 8bba41b commit b21dce5

File tree

44 files changed

+500
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+500
-290
lines changed

packages/cross_file/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 0.3.4
22

3-
* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.
3+
* Updates to web code to package `web: ^0.5.0`.
4+
* Updates SDK version to Dart `^3.3.0`.
45

56
## 0.3.3+8
67

packages/cross_file/lib/src/types/html.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ class XFile extends XFileBase {
6666
super(path) {
6767
if (path == null) {
6868
_browserBlob = _createBlobFromBytes(bytes, mimeType);
69-
// TODO(kevmoo): drop ignore when pkg:web constraint excludes v0.3
70-
// ignore: unnecessary_cast
71-
_path = URL.createObjectURL(_browserBlob! as JSObject);
69+
_path = URL.createObjectURL(_browserBlob!);
7270
} else {
7371
_path = path;
7472
}
@@ -131,9 +129,7 @@ class XFile extends XFileBase {
131129

132130
// Attempt to re-hydrate the blob from the `path` via a (local) HttpRequest.
133131
// Note that safari hangs if the Blob is >=4GB, so bail out in that case.
134-
// TODO(kevmoo): Remove ignore and fix when the MIN Dart SDK is 3.3
135-
// ignore: unnecessary_non_null_assertion
136-
if (isSafari() && _length != null && _length! >= _fourGigabytes) {
132+
if (isSafari() && _length != null && _length >= _fourGigabytes) {
137133
throw Exception('Safari cannot handle XFiles larger than 4GB.');
138134
}
139135

packages/cross_file/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ name: cross_file
22
description: An abstraction to allow working with files across multiple platforms.
33
repository: https://github.com/flutter/packages/tree/main/packages/cross_file
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+cross_file%22
5-
version: 0.3.3+8
5+
version: 0.3.4
66

77
environment:
8-
sdk: ^3.2.0
8+
sdk: ^3.3.0
99

1010
dependencies:
1111
meta: ^1.3.0
12-
web: '>=0.3.0 <0.5.0'
12+
web: ^0.5.0
1313

1414
dev_dependencies:
1515
path: ^1.8.1

packages/cross_file/test/x_file_html_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ void main() {
6969
test('Stores data as a Blob', () async {
7070
// Read the blob from its path 'natively'
7171
final html.Response response =
72-
(await html.window.fetch(file.path.toJS).toDart)! as html.Response;
72+
await html.window.fetch(file.path.toJS).toDart;
7373

74-
final JSAny? arrayBuffer = await response.arrayBuffer().toDart;
75-
final ByteBuffer data = (arrayBuffer! as JSArrayBuffer).toDart;
74+
final JSAny arrayBuffer = await response.arrayBuffer().toDart;
75+
final ByteBuffer data = (arrayBuffer as JSArrayBuffer).toDart;
7676
expect(data.asUint8List(), equals(bytes));
7777
});
7878

packages/file_selector/file_selector_web/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
## NEXT
1+
## 0.9.4
22

3-
* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.
3+
* Updates web code to package `web: ^0.5.0`.
4+
* Updates SDK version to Dart `^3.3.0`. Flutter `^3.16.0`.
45

56
## 0.9.3
67

packages/file_selector/file_selector_web/example/integration_test/dom_helper_test.dart

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ void main() {
1818

1919
FileList? createFileList(List<File> files) {
2020
final DataTransfer dataTransfer = DataTransfer();
21+
// Tear-offs of external extension type interop member 'add' are disallowed.
22+
// ignore: prefer_foreach
2123
for (final File e in files) {
22-
// TODO(srujzs): This is necessary in order to support package:web 0.4.0.
23-
// This was not needed with 0.3.0, hence the lint.
24-
// ignore: unnecessary_cast
25-
dataTransfer.items.add(e as JSAny);
24+
dataTransfer.items.add(e);
2625
}
2726
return dataTransfer.files;
2827
}
@@ -46,13 +45,8 @@ void main() {
4645
});
4746

4847
group('getFiles', () {
49-
final File mockFile1 =
50-
// TODO(srujzs): Remove once typed JSArrays (JSArray<T>) get to `stable`.
51-
// ignore: always_specify_types
52-
File(<Object>['123456'].jsify as JSArray, 'file1.txt');
53-
// TODO(srujzs): Remove once typed JSArrays (JSArray<T>) get to `stable`.
54-
// ignore: always_specify_types
55-
final File mockFile2 = File(<Object>[].jsify as JSArray, 'file2.txt');
48+
final File mockFile1 = File(<JSAny>['123456'.toJS].toJS, 'file1.txt');
49+
final File mockFile2 = File(<JSAny>[].toJS, 'file2.txt');
5650

5751
testWidgets('works', (_) async {
5852
final Future<List<XFile>> futureFiles = domHelper.getFiles(
@@ -114,32 +108,27 @@ void main() {
114108
testWidgets('sets the <input /> attributes and clicks it', (_) async {
115109
const String accept = '.jpg,.png';
116110
const bool multiple = true;
117-
bool wasClicked = false;
118-
119-
//ignore: unawaited_futures
120-
input.onClick.first.then((_) => wasClicked = true);
111+
final Future<bool> wasClicked = input.onClick.first.then((_) => true);
121112

122113
final Future<List<XFile>> futureFile = domHelper.getFiles(
123114
accept: accept,
124115
multiple: multiple,
125116
input: input,
126117
);
127118

128-
expect(input.matches('body'), true);
119+
expect(input.isConnected, true,
120+
reason: 'input must be injected into the DOM');
129121
expect(input.accept, accept);
130122
expect(input.multiple, multiple);
131-
expect(
132-
wasClicked,
133-
true,
134-
reason:
135-
'The <input /> should be clicked otherwise no dialog will be shown',
136-
);
123+
expect(await wasClicked, true,
124+
reason:
125+
'The <input /> should be clicked otherwise no dialog will be shown');
137126

138127
setFilesAndTriggerChange(<File>[]);
139128
await futureFile;
140129

141130
// It should be already removed from the DOM after the file is resolved.
142-
expect(input.parentElement, isNull);
131+
expect(input.isConnected, isFalse);
143132
});
144133
});
145134
});

packages/file_selector/file_selector_web/example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ name: file_selector_web_integration_tests
22
publish_to: none
33

44
environment:
5-
sdk: ^3.1.0
6-
flutter: ">=3.13.0"
5+
sdk: ^3.3.0
6+
flutter: ">=3.19.0"
77

88
dependencies:
99
file_selector_platform_interface: ^2.6.0
1010
file_selector_web:
1111
path: ../
1212
flutter:
1313
sdk: flutter
14-
web: '>=0.3.0 <0.5.0'
14+
web: ^0.5.0
1515

1616
dev_dependencies:
1717
flutter_test:

packages/file_selector/file_selector_web/lib/src/dom_helper.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import 'package:web/helpers.dart';
1414
class DomHelper {
1515
/// Default constructor, initializes the container DOM element.
1616
DomHelper() {
17-
final Element body = querySelector('body')!;
17+
final Element body = document.querySelector('body')!;
1818
body.appendChild(_container);
1919
}
2020

21-
final Element _container = createElementTag('file-selector');
21+
final Element _container = document.createElement('file-selector');
2222

2323
/// Sets the <input /> attributes and waits for a file to be selected.
2424
Future<List<XFile>> getFiles({
@@ -28,7 +28,7 @@ class DomHelper {
2828
}) {
2929
final Completer<List<XFile>> completer = Completer<List<XFile>>();
3030
final HTMLInputElement inputElement =
31-
input ?? (createElementTag('input') as HTMLInputElement)
31+
input ?? (document.createElement('input') as HTMLInputElement)
3232
..type = 'file';
3333

3434
_container.appendChild(
@@ -72,10 +72,7 @@ class DomHelper {
7272
}
7373

7474
XFile _convertFileToXFile(File file) => XFile(
75-
// TODO(srujzs): This is necessary in order to support package:web 0.4.0.
76-
// This was not needed with 0.3.0, hence the lint.
77-
// ignore: unnecessary_cast
78-
URL.createObjectURL(file as JSObject),
75+
URL.createObjectURL(file),
7976
name: file.name,
8077
length: file.size,
8178
lastModified: DateTime.fromMillisecondsSinceEpoch(file.lastModified),

packages/file_selector/file_selector_web/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: file_selector_web
22
description: Web platform implementation of file_selector
33
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
5-
version: 0.9.3
5+
version: 0.9.4
66

77
environment:
8-
sdk: ^3.2.0
9-
flutter: ">=3.16.0"
8+
sdk: ^3.3.0
9+
flutter: ">=3.19.0"
1010

1111
flutter:
1212
plugin:
@@ -22,7 +22,7 @@ dependencies:
2222
sdk: flutter
2323
flutter_web_plugins:
2424
sdk: flutter
25-
web: '>=0.3.0 <0.5.0'
25+
web: ^0.5.0
2626

2727
dev_dependencies:
2828
flutter_test:

packages/google_identity_services_web/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.1
2+
3+
* Updates web code to package `web: ^0.5.0`.
4+
* Updates SDK version to Dart `^3.3.0`. Flutter `^3.19.0`.
5+
16
## 0.3.0+2
27

38
* Adds `fedcm_auto` to `CredentialSelectBy` enum.

packages/google_identity_services_web/example/integration_test/js_interop_id_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ void main() async {
6666
expectConfigValue('login_uri', 'https://www.example.com/login');
6767
expectConfigValue('native_callback', utils.isAJs('function'));
6868
expectConfigValue('cancel_on_tap_outside', isFalse);
69-
// TODO(srujzs): Remove once typed JSArrays (JSArray<T>) get to `stable`.
70-
// ignore: always_specify_types
71-
expectConfigValue('allowed_parent_origin', isA<JSArray>());
69+
expectConfigValue('allowed_parent_origin', isA<JSArray<JSString>>());
7270
expectConfigValue('prompt_parent_id', 'some_dom_id');
7371
expectConfigValue('nonce', 's0m3_r4ndOM_vALu3');
7472
expectConfigValue('context', 'signin');

packages/google_identity_services_web/example/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: google_identity_services_web_example
22
description: An example for the google_identity_services_web package, OneTap.
33
publish_to: 'none'
4-
version: 0.0.1
54

65
environment:
76
flutter: ">=3.16.0"
@@ -13,7 +12,7 @@ dependencies:
1312
google_identity_services_web:
1413
path: ../
1514
http: ">=0.13.0 <2.0.0"
16-
web: ">=0.3.0 <0.5.0"
15+
web: ^0.5.0
1716

1817
dev_dependencies:
1918
build_runner: ^2.1.10 # To extract README excerpts only.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,7 @@ abstract class IdConfiguration {
338338
JSString? context,
339339
JSString? state_cookie_domain,
340340
JSString? ux_mode,
341-
// TODO(srujzs): Remove once typed JSArrays (JSArray<T>) get to `stable`.
342-
// ignore: always_specify_types
343-
JSArray? allowed_parent_origin,
341+
JSArray<JSString>? allowed_parent_origin,
344342
JSFunction? intermediate_iframe_close_callback,
345343
JSBoolean? itp_support,
346344
JSString? login_hint,

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

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,75 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
/// Provides some useful tweaks to `package:web`.
6-
library package_web_tweaks;
7-
85
import 'dart:js_interop';
6+
97
import 'package:web/web.dart' as web;
108

9+
// TODO(kevmoo): Make this file unnecessary, https://github.com/dart-lang/web/issues/175
10+
1111
/// This extension gives web.window a nullable getter to the `trustedTypes`
1212
/// property, which needs to be used to check for feature support.
1313
extension NullableTrustedTypesGetter on web.Window {
14+
/// (Nullable) Bindings to window.trustedTypes.
15+
///
16+
/// This may be null if the browser doesn't support the Trusted Types API.
17+
///
18+
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API
19+
@JS('trustedTypes')
20+
external TrustedTypePolicyFactory? get nullableTrustedTypes;
21+
22+
/// Bindings to window.trustedTypes.
23+
///
24+
/// This will crash if accessed in a browser that doesn't support the
25+
/// Trusted Types API.
1426
///
27+
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API
1528
@JS('trustedTypes')
16-
external web.TrustedTypePolicyFactory? get nullableTrustedTypes;
29+
external TrustedTypePolicyFactory get trustedTypes;
1730
}
1831

19-
/// This extension allows a trusted type policy to create a script URL without
20-
/// the `args` parameter (which in Chrome currently fails).
21-
extension CreateScriptUrlWithoutArgs on web.TrustedTypePolicy {
32+
/// This extension allows setting a TrustedScriptURL as the src of a script element,
33+
/// which currently only accepts a string.
34+
extension TrustedTypeSrcAttribute on web.HTMLScriptElement {
35+
@JS('src')
36+
external set trustedSrc(TrustedScriptURL value);
37+
}
38+
39+
// TODO(kevmoo): drop all of this once `pkg:web` publishes `0.5.1`.
40+
41+
/// Bindings to a JS TrustedScriptURL.
42+
///
43+
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedScriptURL
44+
extension type TrustedScriptURL._(JSObject _) implements JSObject {}
45+
46+
/// Bindings to a JS TrustedTypePolicyFactory.
47+
///
48+
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicyFactory
49+
extension type TrustedTypePolicyFactory._(JSObject _) implements JSObject {
50+
///
51+
external TrustedTypePolicy createPolicy(
52+
String policyName, [
53+
TrustedTypePolicyOptions policyOptions,
54+
]);
55+
}
56+
57+
/// Bindings to a JS TrustedTypePolicy.
58+
///
59+
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy
60+
extension type TrustedTypePolicy._(JSObject _) implements JSObject {
2261
///
2362
@JS('createScriptURL')
24-
external web.TrustedScriptURL createScriptURLNoArgs(
63+
external TrustedScriptURL createScriptURLNoArgs(
2564
String input,
2665
);
2766
}
2867

29-
/// This extension allows setting a TrustedScriptURL as the src of a script element,
30-
/// which currently only accepts a string.
31-
extension TrustedTypeSrcAttribute on web.HTMLScriptElement {
68+
/// Bindings to a JS TrustedTypePolicyOptions (anonymous).
69+
///
70+
/// See: https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicyFactory/createPolicy#policyoptions
71+
extension type TrustedTypePolicyOptions._(JSObject _) implements JSObject {
3272
///
33-
@JS('src')
34-
external set srcTT(web.TrustedScriptURL value);
73+
external factory TrustedTypePolicyOptions({
74+
JSFunction createScriptURL,
75+
});
3576
}

packages/google_identity_services_web/lib/src/js_loader.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ Future<void> loadWebSdk({
2525
onGoogleLibraryLoad = () => completer.complete();
2626

2727
// If TrustedTypes are available, prepare a trusted URL.
28-
web.TrustedScriptURL? trustedUrl;
28+
TrustedScriptURL? trustedUrl;
2929
if (web.window.nullableTrustedTypes != null) {
3030
web.console.debug(
3131
'TrustedTypes available. Creating policy: $trustedTypePolicyName'.toJS,
3232
);
3333
try {
34-
final web.TrustedTypePolicy policy = web.window.trustedTypes.createPolicy(
34+
final TrustedTypePolicy policy = web.window.trustedTypes.createPolicy(
3535
trustedTypePolicyName,
36-
web.TrustedTypePolicyOptions(
36+
TrustedTypePolicyOptions(
3737
createScriptURL: ((JSString url) => _url).toJS,
3838
));
3939
trustedUrl = policy.createScriptURLNoArgs(_url);
@@ -47,7 +47,7 @@ Future<void> loadWebSdk({
4747
..async = true
4848
..defer = true;
4949
if (trustedUrl != null) {
50-
script.srcTT = trustedUrl;
50+
script.trustedSrc = trustedUrl;
5151
} else {
5252
script.src = _url;
5353
}

0 commit comments

Comments
 (0)