mirror of
https://github.com/flutter/packages.git
synced 2025-07-04 09:38:17 +08:00
[web] Removes a few deprecated API usages. (#6177)
This PR removes a bunch of deprecated APIs from the following packages: * `web_benchmarks` * `file_selector_web` * `cross_file` * `image_picker_platform_interface` ## Issues * Fixes https://github.com/flutter/flutter/issues/143113 * Fixes https://github.com/flutter/flutter/issues/143399 * Fixes https://github.com/flutter/flutter/issues/143878 * Fixes https://github.com/flutter/flutter/issues/143892 * Closes https://github.com/flutter/packages/pull/5248
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
## 0.3.4+1
|
||||||
|
|
||||||
|
* Removes a few deprecated API usages.
|
||||||
|
|
||||||
## 0.3.4
|
## 0.3.4
|
||||||
|
|
||||||
* Updates to web code to package `web: ^0.5.0`.
|
* Updates to web code to package `web: ^0.5.0`.
|
||||||
|
@ -8,7 +8,7 @@ import 'dart:js_interop';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:meta/meta.dart';
|
import 'package:meta/meta.dart';
|
||||||
import 'package:web/helpers.dart';
|
import 'package:web/web.dart';
|
||||||
|
|
||||||
import '../web_helpers/web_helpers.dart';
|
import '../web_helpers/web_helpers.dart';
|
||||||
import 'base.dart';
|
import 'base.dart';
|
||||||
@ -133,22 +133,26 @@ class XFile extends XFileBase {
|
|||||||
throw Exception('Safari cannot handle XFiles larger than 4GB.');
|
throw Exception('Safari cannot handle XFiles larger than 4GB.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Completer<Blob> blobCompleter = Completer<Blob>();
|
||||||
|
|
||||||
late XMLHttpRequest request;
|
late XMLHttpRequest request;
|
||||||
try {
|
request = XMLHttpRequest()
|
||||||
request = await HttpRequest.request(path, responseType: 'blob');
|
..open('get', path, true)
|
||||||
} on ProgressEvent catch (e) {
|
..responseType = 'blob'
|
||||||
if (e.type == 'error') {
|
..onLoad.listen((ProgressEvent e) {
|
||||||
throw Exception(
|
assert(request.response != null,
|
||||||
'Could not load Blob from its URL. Has it been revoked?');
|
'The Blob backing this XFile cannot be null!');
|
||||||
}
|
blobCompleter.complete(request.response! as Blob);
|
||||||
rethrow;
|
})
|
||||||
}
|
..onError.listen((ProgressEvent e) {
|
||||||
|
if (e.type == 'error') {
|
||||||
|
blobCompleter.completeError(Exception(
|
||||||
|
'Could not load Blob from its URL. Has it been revoked?'));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
..send();
|
||||||
|
|
||||||
_browserBlob = request.response as Blob?;
|
return blobCompleter.future;
|
||||||
|
|
||||||
assert(_browserBlob != null, 'The Blob backing this XFile cannot be null!');
|
|
||||||
|
|
||||||
return _browserBlob!;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:web/helpers.dart';
|
import 'package:web/web.dart';
|
||||||
|
|
||||||
/// Create anchor element with download attribute
|
/// Create anchor element with download attribute
|
||||||
HTMLAnchorElement createAnchorElement(String href, String? suggestedName) =>
|
HTMLAnchorElement createAnchorElement(String href, String? suggestedName) =>
|
||||||
@ -20,11 +20,11 @@ void addElementToContainerAndClick(Element container, HTMLElement element) {
|
|||||||
|
|
||||||
/// Initializes a DOM container where elements can be injected.
|
/// Initializes a DOM container where elements can be injected.
|
||||||
Element ensureInitialized(String id) {
|
Element ensureInitialized(String id) {
|
||||||
Element? target = querySelector('#$id');
|
Element? target = document.querySelector('#$id');
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
final Element targetElement = document.createElement('flt-x-file')..id = id;
|
final Element targetElement = document.createElement('flt-x-file')..id = id;
|
||||||
|
|
||||||
querySelector('body')!.appendChild(targetElement);
|
document.body!.appendChild(targetElement);
|
||||||
target = targetElement;
|
target = targetElement;
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
|
@ -2,7 +2,7 @@ name: cross_file
|
|||||||
description: An abstraction to allow working with files across multiple platforms.
|
description: An abstraction to allow working with files across multiple platforms.
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/cross_file
|
repository: https://github.com/flutter/packages/tree/main/packages/cross_file
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+cross_file%22
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+cross_file%22
|
||||||
version: 0.3.4
|
version: 0.3.4+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.3.0
|
sdk: ^3.3.0
|
||||||
|
@ -11,7 +11,7 @@ import 'dart:typed_data';
|
|||||||
|
|
||||||
import 'package:cross_file/cross_file.dart';
|
import 'package:cross_file/cross_file.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:web/helpers.dart' as html;
|
import 'package:web/web.dart' as html;
|
||||||
|
|
||||||
const String expectedStringContents = 'Hello, world! I ❤ ñ! 空手';
|
const String expectedStringContents = 'Hello, world! I ❤ ñ! 空手';
|
||||||
final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents));
|
final Uint8List bytes = Uint8List.fromList(utf8.encode(expectedStringContents));
|
||||||
@ -95,7 +95,7 @@ void main() {
|
|||||||
await file.saveTo('');
|
await file.saveTo('');
|
||||||
|
|
||||||
final html.Element? container =
|
final html.Element? container =
|
||||||
html.querySelector('#$crossFileDomElementId');
|
html.document.querySelector('#$crossFileDomElementId');
|
||||||
|
|
||||||
expect(container, isNotNull);
|
expect(container, isNotNull);
|
||||||
});
|
});
|
||||||
@ -106,7 +106,7 @@ void main() {
|
|||||||
await file.saveTo('path');
|
await file.saveTo('path');
|
||||||
|
|
||||||
final html.Element container =
|
final html.Element container =
|
||||||
html.querySelector('#$crossFileDomElementId')!;
|
html.document.querySelector('#$crossFileDomElementId')!;
|
||||||
|
|
||||||
late html.HTMLAnchorElement element;
|
late html.HTMLAnchorElement element;
|
||||||
for (int i = 0; i < container.childNodes.length; i++) {
|
for (int i = 0; i < container.childNodes.length; i++) {
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
## 0.9.4+1
|
||||||
|
|
||||||
|
* Removes a few deprecated API usages.
|
||||||
|
|
||||||
## 0.9.4
|
## 0.9.4
|
||||||
|
|
||||||
* Updates web code to package `web: ^0.5.0`.
|
* Updates web code to package `web: ^0.5.0`.
|
||||||
|
@ -8,7 +8,7 @@ import 'package:file_selector_platform_interface/file_selector_platform_interfac
|
|||||||
import 'package:file_selector_web/src/dom_helper.dart';
|
import 'package:file_selector_web/src/dom_helper.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
import 'package:web/helpers.dart';
|
import 'package:web/web.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('dom_helper', () {
|
group('dom_helper', () {
|
||||||
@ -41,7 +41,8 @@ void main() {
|
|||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
domHelper = DomHelper();
|
domHelper = DomHelper();
|
||||||
input = (createElementTag('input') as HTMLInputElement)..type = 'file';
|
input = (document.createElement('input') as HTMLInputElement)
|
||||||
|
..type = 'file';
|
||||||
});
|
});
|
||||||
|
|
||||||
group('getFiles', () {
|
group('getFiles', () {
|
||||||
|
@ -9,7 +9,7 @@ import 'package:file_selector_web/file_selector_web.dart';
|
|||||||
import 'package:file_selector_web/src/dom_helper.dart';
|
import 'package:file_selector_web/src/dom_helper.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
import 'package:web/helpers.dart';
|
import 'package:web/web.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('FileSelectorWeb', () {
|
group('FileSelectorWeb', () {
|
||||||
|
@ -8,7 +8,7 @@ import 'dart:js_interop';
|
|||||||
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';
|
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';
|
||||||
import 'package:flutter/foundation.dart' show visibleForTesting;
|
import 'package:flutter/foundation.dart' show visibleForTesting;
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:web/helpers.dart';
|
import 'package:web/web.dart';
|
||||||
|
|
||||||
/// Class to manipulate the DOM with the intention of reading files from it.
|
/// Class to manipulate the DOM with the intention of reading files from it.
|
||||||
class DomHelper {
|
class DomHelper {
|
||||||
|
@ -2,7 +2,7 @@ name: file_selector_web
|
|||||||
description: Web platform implementation of file_selector
|
description: Web platform implementation of file_selector
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_web
|
repository: https://github.com/flutter/packages/tree/main/packages/file_selector/file_selector_web
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
|
||||||
version: 0.9.4
|
version: 0.9.4+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.3.0
|
sdk: ^3.3.0
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
## NEXT
|
## 2.9.4
|
||||||
|
|
||||||
* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.
|
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
|
||||||
|
* Removes a few deprecated API usages.
|
||||||
|
|
||||||
## 2.9.3
|
## 2.9.3
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class PickedFile extends PickedFileBase {
|
|||||||
|
|
||||||
Future<Uint8List> get _bytes async {
|
Future<Uint8List> get _bytes async {
|
||||||
if (_initBytes != null) {
|
if (_initBytes != null) {
|
||||||
return Future<Uint8List>.value(UnmodifiableUint8ListView(_initBytes!));
|
return _initBytes.asUnmodifiableView();
|
||||||
}
|
}
|
||||||
return http.readBytes(Uri.parse(path));
|
return http.readBytes(Uri.parse(path));
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@ repository: https://github.com/flutter/packages/tree/main/packages/image_picker/
|
|||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
|
||||||
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
|
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
|
||||||
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
|
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
|
||||||
version: 2.9.3
|
version: 2.9.4
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.1.0
|
sdk: ^3.3.0
|
||||||
flutter: ">=3.13.0"
|
flutter: ">=3.19.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
cross_file: ^0.3.1+1
|
cross_file: ^0.3.1+1
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
## 1.2.1
|
||||||
|
|
||||||
|
* Removes a few deprecated API usages.
|
||||||
|
|
||||||
## 1.2.0
|
## 1.2.0
|
||||||
|
|
||||||
* Updates to web code to package `web: ^0.5.0`.
|
* Updates to web code to package `web: ^0.5.0`.
|
||||||
|
@ -318,7 +318,7 @@ class LocalBenchmarkServerClient {
|
|||||||
/// DevTools Protocol.
|
/// DevTools Protocol.
|
||||||
Future<void> startPerformanceTracing(String? benchmarkName) async {
|
Future<void> startPerformanceTracing(String? benchmarkName) async {
|
||||||
_checkNotManualMode();
|
_checkNotManualMode();
|
||||||
await HttpRequest.request(
|
await _requestXhr(
|
||||||
'/start-performance-tracing?label=$benchmarkName',
|
'/start-performance-tracing?label=$benchmarkName',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mimeType: 'application/json',
|
mimeType: 'application/json',
|
||||||
@ -328,7 +328,7 @@ class LocalBenchmarkServerClient {
|
|||||||
/// Stops the performance tracing session started by [startPerformanceTracing].
|
/// Stops the performance tracing session started by [startPerformanceTracing].
|
||||||
Future<void> stopPerformanceTracing() async {
|
Future<void> stopPerformanceTracing() async {
|
||||||
_checkNotManualMode();
|
_checkNotManualMode();
|
||||||
await HttpRequest.request(
|
await _requestXhr(
|
||||||
'/stop-performance-tracing',
|
'/stop-performance-tracing',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mimeType: 'application/json',
|
mimeType: 'application/json',
|
||||||
@ -356,7 +356,7 @@ class LocalBenchmarkServerClient {
|
|||||||
/// The server will halt the devicelab task and log the error.
|
/// The server will halt the devicelab task and log the error.
|
||||||
Future<void> reportError(dynamic error, StackTrace stackTrace) async {
|
Future<void> reportError(dynamic error, StackTrace stackTrace) async {
|
||||||
_checkNotManualMode();
|
_checkNotManualMode();
|
||||||
await HttpRequest.request(
|
await _requestXhr(
|
||||||
'/on-error',
|
'/on-error',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mimeType: 'application/json',
|
mimeType: 'application/json',
|
||||||
@ -370,7 +370,7 @@ class LocalBenchmarkServerClient {
|
|||||||
/// Reports a message about the demo to the benchmark server.
|
/// Reports a message about the demo to the benchmark server.
|
||||||
Future<void> printToConsole(String report) async {
|
Future<void> printToConsole(String report) async {
|
||||||
_checkNotManualMode();
|
_checkNotManualMode();
|
||||||
await HttpRequest.request(
|
await _requestXhr(
|
||||||
'/print-to-console',
|
'/print-to-console',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
mimeType: 'text/plain',
|
mimeType: 'text/plain',
|
||||||
@ -384,7 +384,7 @@ class LocalBenchmarkServerClient {
|
|||||||
String url, {
|
String url, {
|
||||||
required String method,
|
required String method,
|
||||||
required String mimeType,
|
required String mimeType,
|
||||||
required String sendData,
|
String? sendData,
|
||||||
}) {
|
}) {
|
||||||
final Completer<XMLHttpRequest> completer = Completer<XMLHttpRequest>();
|
final Completer<XMLHttpRequest> completer = Completer<XMLHttpRequest>();
|
||||||
final XMLHttpRequest xhr = XMLHttpRequest();
|
final XMLHttpRequest xhr = XMLHttpRequest();
|
||||||
@ -394,7 +394,11 @@ class LocalBenchmarkServerClient {
|
|||||||
completer.complete(xhr);
|
completer.complete(xhr);
|
||||||
});
|
});
|
||||||
xhr.onError.listen(completer.completeError);
|
xhr.onError.listen(completer.completeError);
|
||||||
xhr.send(sendData.toJS);
|
if (sendData != null) {
|
||||||
|
xhr.send(sendData.toJS);
|
||||||
|
} else {
|
||||||
|
xhr.send();
|
||||||
|
}
|
||||||
return completer.future;
|
return completer.future;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,6 +248,7 @@ abstract class SceneBuilderRecorder extends Recorder {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
PlatformDispatcher.instance.onDrawFrame = () {
|
PlatformDispatcher.instance.onDrawFrame = () {
|
||||||
|
final FlutterView? view = PlatformDispatcher.instance.implicitView;
|
||||||
try {
|
try {
|
||||||
_profile.record('drawFrameDuration', () {
|
_profile.record('drawFrameDuration', () {
|
||||||
final SceneBuilder sceneBuilder = SceneBuilder();
|
final SceneBuilder sceneBuilder = SceneBuilder();
|
||||||
@ -255,7 +256,9 @@ abstract class SceneBuilderRecorder extends Recorder {
|
|||||||
_profile.record('sceneBuildDuration', () {
|
_profile.record('sceneBuildDuration', () {
|
||||||
final Scene scene = sceneBuilder.build();
|
final Scene scene = sceneBuilder.build();
|
||||||
_profile.record('windowRenderDuration', () {
|
_profile.record('windowRenderDuration', () {
|
||||||
window.render(scene);
|
assert(view != null,
|
||||||
|
'Cannot profile windowRenderDuration on a null View.');
|
||||||
|
view!.render(scene);
|
||||||
}, reported: false);
|
}, reported: false);
|
||||||
}, reported: false);
|
}, reported: false);
|
||||||
}, reported: true);
|
}, reported: true);
|
||||||
|
@ -2,7 +2,7 @@ name: web_benchmarks
|
|||||||
description: A benchmark harness for performance-testing Flutter apps in Chrome.
|
description: A benchmark harness for performance-testing Flutter apps in Chrome.
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/web_benchmarks
|
repository: https://github.com/flutter/packages/tree/main/packages/web_benchmarks
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+web_benchmarks%22
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+web_benchmarks%22
|
||||||
version: 1.2.0
|
version: 1.2.1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.3.0
|
sdk: ^3.3.0
|
||||||
@ -14,7 +14,6 @@ dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
http: ^1.0.0
|
|
||||||
logging: ^1.0.2
|
logging: ^1.0.2
|
||||||
meta: ^1.7.0
|
meta: ^1.7.0
|
||||||
path: ^1.8.0
|
path: ^1.8.0
|
||||||
|
Reference in New Issue
Block a user