[web] Remove deprecated web-only APIs from dart:ui (#161775)

These web-only APIs have been moved to `dart:ui_web` ages ago
(https://github.com/flutter/flutter/issues/126831).

Closes https://github.com/flutter/flutter/issues/127395
This commit is contained in:
Mouad Debbar 2025-01-22 14:51:07 -05:00 committed by GitHub
parent a1d02b657e
commit c289c638fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 2 additions and 335 deletions

View File

@ -41149,7 +41149,6 @@ ORIGIN: ../../../flutter/lib/web_ui/lib/canvas.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/channel_buffers.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/compositing.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/geometry.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/initialization.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/key.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/lerp.dart + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/lib/web_ui/lib/math.dart + ../../../flutter/LICENSE
@ -44097,7 +44096,6 @@ FILE: ../../../flutter/lib/web_ui/lib/canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/channel_buffers.dart
FILE: ../../../flutter/lib/web_ui/lib/compositing.dart
FILE: ../../../flutter/lib/web_ui/lib/geometry.dart
FILE: ../../../flutter/lib/web_ui/lib/initialization.dart
FILE: ../../../flutter/lib/web_ui/lib/key.dart
FILE: ../../../flutter/lib/web_ui/lib/lerp.dart
FILE: ../../../flutter/lib/web_ui/lib/math.dart

View File

@ -1,104 +0,0 @@
// 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.
// TODO(yjbanov): rename this file to web_only_api.dart.
// https://github.com/flutter/flutter/issues/100394
// Rather than extending this file with new APIs, we
// should instead use js interop.
// This file contains extra web-only API that non-web engines do not have.
//
// Why have web-only API?
//
// Because all Dart code is compiled (and tree shaken) as a single compilation
// unit it only has one entry-point - the `main()` function of the Flutter
// app. The top-level `main()` is generated by Flutter tool and it needs to
// ask the engine to initialize itself before calling the handwritten `main()`
// function of the app itself. To do that, it needs something to call. The
// mobile engine doesn't provide a function like that because the application
// starts from the Java (Android) or Objective-C (iOS). Any initial
// configuration can be done in Java and the engine's C++ code prior to
// calling Dart's `main()`.
part of ui;
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
Future<void> webOnlyWarmupEngine({VoidCallback? registerPlugins, VoidCallback? runApp}) {
assert(() {
engine.printWarning(
'The webOnlyWarmupEngine API is deprecated and will be removed in a '
'future release. Please use `bootstrapEngine` from `dart:ui_web` instead.',
);
return true;
}());
return ui_web.bootstrapEngine(registerPlugins: registerPlugins, runApp: runApp);
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
bool get debugEmulateFlutterTesterEnvironment {
assert(() {
engine.printWarning(
'The debugEmulateFlutterTesterEnvironment getter is deprecated and will '
'be removed in a future release. Please use '
'`debugEmulateFlutterTesterEnvironment` from `dart:ui_web` instead.',
);
return true;
}());
return ui_web.debugEmulateFlutterTesterEnvironment;
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
set debugEmulateFlutterTesterEnvironment(bool value) {
assert(() {
engine.printWarning(
'The debugEmulateFlutterTesterEnvironment setter is deprecated and will '
'be removed in a future release. Please use '
'`debugEmulateFlutterTesterEnvironment` from `dart:ui_web` instead.',
);
return true;
}());
ui_web.debugEmulateFlutterTesterEnvironment = value;
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
ui_web.AssetManager get webOnlyAssetManager {
assert(() {
engine.printWarning(
'The webOnlyAssetManager getter is deprecated and will be removed in a '
'future release. Please use `assetManager` from `dart:ui_web` instead.',
);
return true;
}());
return ui_web.assetManager;
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
void webOnlySetPluginHandler(PlatformMessageCallback handler) {
assert(() {
engine.printWarning(
'The webOnlySetPluginHandler API is deprecated and will be removed in a '
'future release. Please use `setPluginHandler` from `dart:ui_web` instead.',
);
return true;
}());
ui_web.setPluginHandler(handler);
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
ui_web.PlatformViewRegistry get platformViewRegistry {
assert(() {
engine.printWarning(
'The platformViewRegistry getter is deprecated and will be removed in a '
'future release. Please import it from `dart:ui_web` instead.',
);
return true;
}());
return ui_web.platformViewRegistry;
}

View File

@ -689,23 +689,6 @@ class TargetImageSize {
final int? height;
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
Future<Codec> webOnlyInstantiateImageCodecFromUrl(
Uri uri, {
ui_web.ImageCodecChunkCallback? chunkCallback,
}) {
assert(() {
engine.printWarning(
'The webOnlyInstantiateImageCodecFromUrl API is deprecated and will be '
'removed in a future release. Please use `createImageCodecFromUrl` from '
'`dart:ui_web` instead.',
);
return true;
}());
return ui_web.createImageCodecFromUrl(uri, chunkCallback: chunkCallback);
}
void decodeImageFromList(Uint8List list, ImageDecoderCallback callback) {
_decodeImageFromListAsync(list, callback);
}

View File

@ -8,10 +8,6 @@ import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
typedef WebOnlyImageCodecChunkCallback = ui_web.ImageCodecChunkCallback;
abstract class HtmlImageElementCodec implements ui.Codec {
HtmlImageElementCodec(this.src, {this.chunkCallback, this.debugSource});

View File

@ -3,17 +3,9 @@
// found in the LICENSE file.
import 'dart:async';
import 'dart:js_interop';
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
import 'util.dart';
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
@JS('window._flutter_internal_on_benchmark')
external JSExportedDartFunction? get jsBenchmarkValueCallback;
ui_web.BenchmarkValueCallback? engineBenchmarkValueCallback;
/// A function that computes a value of type [R].
@ -59,8 +51,8 @@ R timeAction<R>(String name, Action<R> action) {
///
/// 1. Set the environment variable `FLUTTER_WEB_ENABLE_PROFILING` to true.
///
/// 2. Using JS interop, assign a listener function to
/// `window._flutter_internal_on_benchmark` in the browser.
/// 2. Set the [engineBenchmarkValueCallback] to a function that will receive
/// the benchmark data.
///
/// The listener function will be called every time a new benchmark number is
/// calculated. The signature is `Function(String name, num value)`.
@ -105,17 +97,6 @@ class Profiler {
void benchmark(String name, double value) {
_checkBenchmarkMode();
final ui_web.BenchmarkValueCallback? callback =
jsBenchmarkValueCallback?.toDart as ui_web.BenchmarkValueCallback?;
if (callback != null) {
printWarning(
'The JavaScript benchmarking API (i.e. `window._flutter_internal_on_benchmark`) '
'is deprecated and will be removed in a future release. Please use '
'`benchmarkValueCallback` from `dart:ui_web` instead.',
);
callback(name, value);
}
if (engineBenchmarkValueCallback != null) {
engineBenchmarkValueCallback!(name, value);
}

View File

@ -656,50 +656,6 @@ final class EngineFlutterWindow extends EngineFlutterView implements ui.Singleto
return false;
});
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
void debugOverrideDevicePixelRatio(double? value) {
assert(() {
printWarning(
'The window.debugOverrideDevicePixelRatio API is deprecated and will '
'be removed in a future release. Please use '
'`debugOverrideDevicePixelRatio` from `dart:ui_web` instead.',
);
return true;
}());
display.debugOverrideDevicePixelRatio(value);
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
ui.Size? get webOnlyDebugPhysicalSizeOverride {
assert(() {
printWarning(
'The webOnlyDebugPhysicalSizeOverride API is deprecated and will be '
'removed in a future release. Please use '
'`SingletonFlutterWindow.debugPhysicalSizeOverride` from `dart:ui_web` '
'instead.',
);
return true;
}());
return debugPhysicalSizeOverride;
}
// TODO(mdebbar): Deprecate this and remove it.
// https://github.com/flutter/flutter/issues/127395
set webOnlyDebugPhysicalSizeOverride(ui.Size? value) {
assert(() {
printWarning(
'The webOnlyDebugPhysicalSizeOverride API is deprecated and will be '
'removed in a future release. Please use '
'`SingletonFlutterWindow.debugPhysicalSizeOverride` from `dart:ui_web` '
'instead.',
);
return true;
}());
debugPhysicalSizeOverride = value;
}
}
/// The window singleton.

View File

@ -14,14 +14,12 @@ import 'dart:math' as math;
import 'dart:typed_data';
import 'src/engine.dart' as engine;
import 'ui_web/src/ui_web.dart' as ui_web;
part 'annotations.dart';
part 'canvas.dart';
part 'channel_buffers.dart';
part 'compositing.dart';
part 'geometry.dart';
part 'initialization.dart';
part 'key.dart';
part 'lerp.dart';
part 'math.dart';

View File

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:js_interop';
import 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
@ -11,9 +9,6 @@ import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
import '../common/spy.dart';
@JS('window._flutter_internal_on_benchmark')
external set jsBenchmarkValueCallback(JSAny? object);
void main() {
internalBootstrapBrowserTest(() => testMain);
}
@ -50,7 +45,6 @@ void _profilerTests() {
});
tearDown(() {
jsBenchmarkValueCallback = null;
ui_web.benchmarkValueCallback = null;
Profiler.isBenchmarkMode = false;
});
@ -79,102 +73,6 @@ void _profilerTests() {
expect(() => Profiler.instance.benchmark('baz', 99.999), returnsNormally);
expect(data, isEmpty);
});
// TODO(mdebbar): Remove this group once the JS API is removed.
// https://github.com/flutter/flutter/issues/127395
group('[JS API]', () {
test('can listen to benchmarks', () {
final List<BenchmarkDatapoint> data = <BenchmarkDatapoint>[];
jsBenchmarkValueCallback =
(String name, double value) {
data.add((name, value));
}.toJS;
Profiler.instance.benchmark('foo', 123);
expect(warnings, hasLength(1));
expect(warnings.single, contains('deprecated'));
expect(warnings.single, contains('benchmarkValueCallback'));
expect(warnings.single, contains('dart:ui_web'));
warnings.clear();
expect(data, <BenchmarkDatapoint>[('foo', 123)]);
data.clear();
Profiler.instance.benchmark('bar', 0.0125);
expect(data, <BenchmarkDatapoint>[('bar', 0.0125)]);
data.clear();
// Remove listener and make sure nothing breaks and the data isn't being
// sent to the old callback anymore.
jsBenchmarkValueCallback = null;
expect(() => Profiler.instance.benchmark('baz', 99.999), returnsNormally);
expect(data, isEmpty);
});
test('throws on wrong listener type', () {
final List<BenchmarkDatapoint> data = <BenchmarkDatapoint>[];
// Wrong callback signature.
jsBenchmarkValueCallback =
(double value) {
data.add(('bad', value));
}.toJS;
expect(
() => Profiler.instance.benchmark('foo', 123),
// dart2js throws a NoSuchMethodError, dart2wasm throws a TypeError here.
// Just make sure it throws an error in this case.
throwsA(isA<Error>()),
);
expect(data, isEmpty);
// Not even a callback.
jsBenchmarkValueCallback = 'string'.toJS;
expect(
() => Profiler.instance.benchmark('foo', 123),
// dart2js throws a TypeError, while dart2wasm throws an explicit
// exception.
throwsA(anything),
);
});
test('can be combined with ui_web API', () {
final List<BenchmarkDatapoint> uiWebData = <BenchmarkDatapoint>[];
final List<BenchmarkDatapoint> jsData = <BenchmarkDatapoint>[];
ui_web.benchmarkValueCallback = (String name, double value) {
uiWebData.add((name, value));
};
jsBenchmarkValueCallback =
(String name, double value) {
jsData.add((name, value));
}.toJS;
Profiler.instance.benchmark('foo', 123);
expect(warnings, hasLength(1));
expect(warnings.single, contains('deprecated'));
expect(warnings.single, contains('benchmarkValueCallback'));
expect(warnings.single, contains('dart:ui_web'));
warnings.clear();
expect(uiWebData, <BenchmarkDatapoint>[('foo', 123)]);
expect(jsData, <BenchmarkDatapoint>[('foo', 123)]);
uiWebData.clear();
jsData.clear();
Profiler.instance.benchmark('bar', 0.0125);
expect(uiWebData, <BenchmarkDatapoint>[('bar', 0.0125)]);
expect(jsData, <BenchmarkDatapoint>[('bar', 0.0125)]);
uiWebData.clear();
jsData.clear();
ui_web.benchmarkValueCallback = null;
jsBenchmarkValueCallback = null;
expect(() => Profiler.instance.benchmark('baz', 99.999), returnsNormally);
expect(uiWebData, isEmpty);
expect(jsData, isEmpty);
});
});
}
void _instrumentationTests() {

View File

@ -1,39 +0,0 @@
// 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 'package:test/bootstrap/browser.dart';
import 'package:test/test.dart';
import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart' as ui;
import 'package:ui/ui_web/src/ui_web.dart' as ui_web;
void main() {
internalBootstrapBrowserTest(() => testMain);
}
Future<void> testMain() async {
test('importing platformViewRegistry from dart:ui is deprecated', () {
final void Function(String) oldPrintWarning = printWarning;
final List<String> warnings = <String>[];
printWarning = (String message) {
warnings.add(message);
};
// ignore: unnecessary_statements
ui_web.platformViewRegistry;
expect(warnings, isEmpty);
// ignore: unnecessary_statements
ui.platformViewRegistry;
expect(warnings, hasLength(1));
expect(warnings.single, contains('platformViewRegistry'));
expect(warnings.single, contains('deprecated'));
expect(warnings.single, contains('dart:ui_web'));
printWarning = oldPrintWarning;
});
}