Move package:web dependency to dev dependency (#139696)

Pinning the package:web dependency constrains downstream packages from
using newer versions and making sure they support the version pinned in
Flutter. Since the usage of package:web in Flutter is light, we should
instead have a small shim like the engine and keep package:web as a dev
dependency only.
This commit is contained in:
Srujan Gaddam
2023-12-15 08:53:27 -08:00
committed by GitHub
parent 8b8d39593d
commit 2407f699e9
61 changed files with 274 additions and 139 deletions

View File

@@ -4,8 +4,7 @@
import 'dart:ui_web' as ui_web;
import 'package:web/web.dart' as web;
import '../web.dart' as web;
import 'platform.dart' as platform;
export 'platform.dart' show TargetPlatform;

View File

@@ -8,8 +8,8 @@ import 'dart:ui' as ui;
import 'dart:ui_web' as ui_web;
import 'package:flutter/foundation.dart';
import 'package:web/web.dart' as web;
import '../web.dart' as web;
import 'image_provider.dart' as image_provider;
import 'image_stream.dart';

View File

@@ -0,0 +1,213 @@
// Copyright 2014 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.
// This code is copied from `package:web` which still needs its own
// documentation for public members. Since this is a shim that users should not
// use, we ignore this lint for this file.
// ignore_for_file: public_member_api_docs
/// A stripped down version of `package:web` to avoid pinning that repo in
/// Flutter as a dependency.
///
/// These are manually copied over from `package:web` as needed, and should stay
/// in sync with the latest package version as much as possible.
///
/// If missing members are needed, copy them over into the corresponding
/// extension or interface. If missing interfaces/types are needed, copy them
/// over while excluding unnecessary inheritance to make the copy minimal. These
/// types are erased at runtime, so excluding supertypes is safe. If a member is
/// needed that belongs to a supertype, then add the necessary `implements`
/// clause to the subtype when you add that supertype. Keep extensions next to
/// the interface they extend.
library;
import 'dart:js_interop';
typedef EventListener = JSFunction;
typedef XMLHttpRequestResponseType = String;
@JS()
external Document get document;
@JS()
external Window get window;
@JS('CSSStyleDeclaration')
@staticInterop
class CSSStyleDeclaration {}
extension CSSStyleDeclarationExtension on CSSStyleDeclaration {
external set backgroundColor(String value);
external String get backgroundColor;
external set border(String value);
external String get border;
external set height(String value);
external String get height;
external set width(String value);
external String get width;
}
@JS('CSSStyleSheet')
@staticInterop
class CSSStyleSheet {}
extension CSSStyleSheetExtension on CSSStyleSheet {
external int insertRule(
String rule, [
int index,
]);
}
@JS('Document')
@staticInterop
class Document implements Node {}
extension DocumentExtension on Document {
external Element createElement(
String localName, [
JSAny options,
]);
external Range createRange();
external HTMLHeadElement? get head;
}
@JS('DOMTokenList')
@staticInterop
class DOMTokenList {}
extension DOMTokenListExtension on DOMTokenList {
external void add(String tokens);
}
@JS('Element')
@staticInterop
class Element implements Node {}
extension ElementExtension on Element {
external DOMTokenList get classList;
external void append(JSAny nodes);
}
@JS('Event')
@staticInterop
class Event {}
@JS('EventTarget')
@staticInterop
class EventTarget {}
extension EventTargetExtension on EventTarget {
external void addEventListener(
String type,
EventListener? callback, [
JSAny options,
]);
}
@JS('HTMLElement')
@staticInterop
class HTMLElement implements Element {}
extension HTMLElementExtension on HTMLElement {
external set innerText(String value);
external CSSStyleDeclaration get style;
}
@JS('HTMLHeadElement')
@staticInterop
class HTMLHeadElement implements HTMLElement {}
@JS('HTMLStyleElement')
@staticInterop
class HTMLStyleElement implements HTMLElement {}
extension HTMLStyleElementExtension on HTMLStyleElement {
external CSSStyleSheet? get sheet;
}
@JS('MediaQueryList')
@staticInterop
class MediaQueryList {}
extension MediaQueryListExtension on MediaQueryList {
external bool get matches;
}
@JS('MouseEvent')
@staticInterop
class MouseEvent {}
extension MouseEventExtension on MouseEvent {
external num get offsetX;
external num get offsetY;
external int get button;
}
@JS('Navigator')
@staticInterop
class Navigator {}
extension NavigatorExtension on Navigator {
external String get platform;
}
@JS('Node')
@staticInterop
class Node implements EventTarget {}
@JS('Range')
@staticInterop
class Range {}
extension RangeExtension on Range {
external void selectNode(Node node);
}
@JS('Selection')
@staticInterop
class Selection {}
extension SelectionExtension on Selection {
external void addRange(Range range);
external void removeAllRanges();
}
@JS('Window')
@staticInterop
class Window {}
extension WindowExtension on Window {
external Navigator get navigator;
external MediaQueryList matchMedia(String query);
external Selection? getSelection();
}
@JS('XMLHttpRequest')
@staticInterop
class XMLHttpRequest implements XMLHttpRequestEventTarget {
external factory XMLHttpRequest();
}
extension XMLHttpRequestExtension on XMLHttpRequest {
external void open(
String method,
String url, [
bool async,
String? username,
String? password,
]);
external void setRequestHeader(
String name,
String value,
);
external void send([JSAny? body]);
external int get status;
external set responseType(XMLHttpRequestResponseType value);
external XMLHttpRequestResponseType get responseType;
external JSAny? get response;
}
@JS('XMLHttpRequestEventTarget')
@staticInterop
class XMLHttpRequestEventTarget implements EventTarget {}

View File

@@ -6,8 +6,8 @@ import 'dart:js_interop';
import 'dart:ui_web' as ui_web;
import 'package:flutter/rendering.dart';
import 'package:web/web.dart' as web;
import '../web.dart' as web;
import 'basic.dart';
import 'framework.dart';
import 'platform_view.dart';

View File

@@ -419,30 +419,6 @@ class HtmlElementView extends StatelessWidget {
///
/// [onElementCreated] is called when the DOM element is created. It can be
/// used by the app to customize the element by adding attributes and styles.
///
/// ```dart
/// import 'package:flutter/widgets.dart';
/// import 'package:web/web.dart' as web;
///
/// // ...
///
/// class MyWidget extends StatelessWidget {
/// const MyWidget({super.key});
///
/// @override
/// Widget build(BuildContext context) {
/// return HtmlElementView.fromTagName(
/// tagName: 'div',
/// onElementCreated: (Object element) {
/// element as web.HTMLElement;
/// element.style
/// ..backgroundColor = 'blue'
/// ..border = '1px solid red';
/// },
/// );
/// }
/// }
/// ```
factory HtmlElementView.fromTagName({
Key? key,
required String tagName,

View File

@@ -12,7 +12,6 @@ dependencies:
material_color_utilities: 0.8.0
meta: 1.11.0
vector_math: 2.1.4
web: 0.4.0
sky_engine:
sdk: flutter
@@ -25,6 +24,7 @@ dev_dependencies:
leak_tracker: 9.0.17
leak_tracker_testing: 1.0.6
leak_tracker_flutter_testing: 1.0.12
web: 0.4.0
async: 2.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
boolean_selector: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"

View File

@@ -5,6 +5,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/painting/_network_image_web.dart';
import 'package:flutter/src/web.dart' as web_shim;
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'package:web/web.dart' as web;
@@ -24,7 +25,7 @@ void runTests() {
..response = (Uint8List.fromList(kTransparentImage)).buffer;
httpRequestFactory = () {
return testHttpRequest.getMock();
return testHttpRequest.getMock() as web_shim.XMLHttpRequest;
};
const Map<String, String> headers = <String, String>{
@@ -50,7 +51,7 @@ void runTests() {
httpRequestFactory = () {
return testHttpRequest.getMock();
return testHttpRequest.getMock() as web_shim.XMLHttpRequest;
};
const Map<String, String> headers = <String, String>{
@@ -75,7 +76,7 @@ void runTests() {
..response = (Uint8List.fromList(<int>[])).buffer;
httpRequestFactory = () {
return testHttpRequest.getMock();
return testHttpRequest.getMock() as web_shim.XMLHttpRequest;
};
const Map<String, String> headers = <String, String>{

View File

@@ -31,7 +31,6 @@ dependencies:
term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
flutter_goldens:
@@ -42,4 +41,4 @@ dev_dependencies:
platform: 3.1.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
process: 5.0.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: c8b7
# PUBSPEC CHECKSUM: d82d

View File

@@ -37,7 +37,6 @@ dependencies:
term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
fake_async: 1.3.1
@@ -74,4 +73,4 @@ dev_dependencies:
webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
yaml: 3.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: 7239
# PUBSPEC CHECKSUM: 46ae

View File

@@ -37,6 +37,5 @@ dependencies:
typed_data: 1.3.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: 4819
# PUBSPEC CHECKSUM: bc8e

View File

@@ -17,7 +17,6 @@ dependencies:
meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
path: 1.9.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
flutter_test:
@@ -37,4 +36,4 @@ dev_dependencies:
test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: 5dfb
# PUBSPEC CHECKSUM: 1871

View File

@@ -45,7 +45,6 @@ dependencies:
string_scanner: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
file: 7.0.0
@@ -53,4 +52,4 @@ dev_dependencies:
# Used to detect memory leaks.
leak_tracker_flutter_testing: 1.0.12
# PUBSPEC CHECKSUM: 0fe2
# PUBSPEC CHECKSUM: bf58

View File

@@ -14,7 +14,6 @@ dependencies:
material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
flutter_test:
@@ -36,4 +35,4 @@ dev_dependencies:
test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vm_service: 13.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: 00c1
# PUBSPEC CHECKSUM: 4737

View File

@@ -17,7 +17,6 @@ dependencies:
material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
flutter_test:
@@ -86,4 +85,4 @@ dev_dependencies:
flutter:
uses-material-design: true
# PUBSPEC CHECKSUM: 80a2
# PUBSPEC CHECKSUM: 1818

View File

@@ -21,9 +21,8 @@ dependencies:
material_color_utilities: 0.8.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
meta: 1.11.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
pedantic: 1.11.1
# PUBSPEC CHECKSUM: 65e5
# PUBSPEC CHECKSUM: d95b

View File

@@ -35,7 +35,6 @@ dependencies:
term_glyph: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
test_api: 0.6.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web: 0.4.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
webdriver: 3.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
flutter:
@@ -47,4 +46,4 @@ flutter:
ios:
pluginClass: IntegrationTestPlugin
# PUBSPEC CHECKSUM: 98f7
# PUBSPEC CHECKSUM: 706d