From bbc0161669677970ff3a7baf03f0e316e5f58e2a Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Mon, 9 Nov 2020 15:26:29 -0800 Subject: [PATCH] Remove references to `Window`, and switch usages to `PlatformDispatcher` or `SingletonFlutterWindow` (#69617) * Remove references to dart:ui.Window, and point usages to PlatformDispatcher or SingletonFlutterWindow, as appropriate * remove new test platform dispatchers * Amend documentation --- .../macrobenchmarks/lib/src/web/recorder.dart | 7 +- .../test_memory/image_cache_memory.dart | 5 +- .../flutter/lib/src/foundation/binding.dart | 68 +++++-- .../flutter/lib/src/foundation/debug.dart | 2 +- .../flutter/lib/src/gestures/binding.dart | 4 +- .../flutter/lib/src/gestures/converter.dart | 6 +- packages/flutter/lib/src/gestures/events.dart | 3 +- packages/flutter/lib/src/material/app.dart | 2 +- .../flutter/lib/src/rendering/binding.dart | 16 +- packages/flutter/lib/src/rendering/layer.dart | 8 +- .../flutter/lib/src/rendering/proxy_box.dart | 6 +- packages/flutter/lib/src/rendering/view.dart | 8 +- .../flutter/lib/src/scheduler/binding.dart | 76 +++---- .../flutter/lib/src/semantics/binding.dart | 6 +- .../flutter/lib/src/semantics/semantics.dart | 4 +- .../lib/src/services/binary_messenger.dart | 2 +- .../flutter/lib/src/services/binding.dart | 27 +-- .../lib/src/services/platform_messages.dart | 2 +- packages/flutter/lib/src/widgets/app.dart | 16 +- packages/flutter/lib/src/widgets/binding.dart | 55 ++--- .../flutter/lib/src/widgets/media_query.dart | 18 +- .../flutter/lib/src/widgets/navigator.dart | 2 +- .../flutter/lib/src/widgets/safe_area.dart | 4 +- .../flutter/test/painting/binding_test.dart | 5 +- .../painting/image_cache_binding_test.dart | 5 +- .../binding_first_frame_rasterized_test.dart | 4 +- .../test/widgets/semantics_tester.dart | 3 +- .../lib/src/common/geometry.dart | 8 +- .../flutter_driver/lib/src/driver/driver.dart | 13 +- .../flutter_test/lib/src/_matchers_web.dart | 2 +- .../flutter_test/lib/src/accessibility.dart | 2 +- packages/flutter_test/lib/src/binding.dart | 16 +- packages/flutter_test/lib/src/window.dart | 191 +++++++++--------- packages/flutter_tools/lib/src/plugins.dart | 2 +- 34 files changed, 331 insertions(+), 267 deletions(-) diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart index 2c5f12084c..8ab48f5ddb 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart @@ -217,15 +217,16 @@ abstract class SceneBuilderRecorder extends Recorder { Profile get profile => _profile; Profile _profile; - /// Called from [Window.onBeginFrame]. + /// Called from [dart:ui.PlatformDispatcher.onBeginFrame]. @mustCallSuper void onBeginFrame() {} /// Called on every frame. /// /// An implementation should exercise the [sceneBuilder] to build a frame. - /// However, it must not call [SceneBuilder.build] or [Window.render]. - /// Instead the benchmark harness will call them and time them appropriately. + /// However, it must not call [SceneBuilder.build] or + /// [dart:ui.FlutterView.render]. Instead the benchmark harness will call them + /// and time them appropriately. void onDrawFrame(SceneBuilder sceneBuilder); @override diff --git a/dev/integration_tests/flutter_gallery/test_memory/image_cache_memory.dart b/dev/integration_tests/flutter_gallery/test_memory/image_cache_memory.dart index 8ef468f6bc..37fea83b9b 100644 --- a/dev/integration_tests/flutter_gallery/test_memory/image_cache_memory.dart +++ b/dev/integration_tests/flutter_gallery/test_memory/image_cache_memory.dart @@ -41,8 +41,9 @@ Future main() async { await SchedulerBinding.instance.endOfFrame; - // We are waiting for the GPU to rasterize a frame here. This makes this flaky, - // we can rely on a more deterministic such as `Window.onReportTimings` once + // We are waiting for the GPU to rasterize a frame here. This makes this + // flaky, we can rely on a more deterministic source such as + // PlatformDispatcher.onReportTimings once // https://github.com/flutter/flutter/issues/26154 is addressed. await Future.delayed(const Duration(milliseconds: 50)); debugPrint('==== MEMORY BENCHMARK ==== READY ===='); diff --git a/packages/flutter/lib/src/foundation/binding.dart b/packages/flutter/lib/src/foundation/binding.dart index 00569c7688..e6c650e77e 100644 --- a/packages/flutter/lib/src/foundation/binding.dart +++ b/packages/flutter/lib/src/foundation/binding.dart @@ -5,7 +5,7 @@ import 'dart:convert' show json; import 'dart:developer' as developer; import 'dart:io' show exit; -import 'dart:ui' as ui show Window, window, Brightness; +import 'dart:ui' as ui show SingletonFlutterWindow, Brightness, PlatformDispatcher, window; // Before adding any more dart:ui imports, please read the README. import 'package:meta/meta.dart'; @@ -68,23 +68,57 @@ abstract class BindingBase { static bool _debugInitialized = false; static bool _debugServiceExtensionsRegistered = false; - /// The window to which this binding is bound. + /// The main window to which this binding is bound. /// - /// A number of additional bindings are defined as extensions of [BindingBase], - /// e.g., [ServicesBinding], [RendererBinding], and [WidgetsBinding]. Each of - /// these bindings define behaviors that interact with a [ui.Window], e.g., - /// [ServicesBinding] registers a [ui.Window.onPlatformMessage] handler, and - /// [RendererBinding] registers [ui.Window.onMetricsChanged], - /// [ui.Window.onTextScaleFactorChanged], [ui.Window.onSemanticsEnabledChanged], - /// and [ui.Window.onSemanticsAction] handlers. + /// A number of additional bindings are defined as extensions of + /// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and + /// [WidgetsBinding]. Each of these bindings define behaviors that interact + /// with a [ui.SingletonFlutterWindow]. /// - /// Each of these other bindings could individually access a [Window] statically, - /// but that would preclude the ability to test these behaviors with a fake - /// window for verification purposes. Therefore, [BindingBase] exposes this - /// [Window] for use by other bindings. A subclass of [BindingBase], such as + /// Each of these other bindings could individually access a + /// [ui.SingletonFlutterWindow] statically, but that would preclude the + /// ability to test its behaviors with a fake window for verification + /// purposes. Therefore, [BindingBase] exposes this + /// [ui.SingletonFlutterWindow] for use by other bindings. A subclass of + /// [BindingBase], such as [TestWidgetsFlutterBinding], can override this + /// accessor to return a different [ui.SingletonFlutterWindow] implementation, + /// such as a [TestWindow]. + /// + /// The `window` is a singleton meant for use by applications that only have a + /// single main window. In addition to the properties of [ui.FlutterWindow], + /// `window` provides access to platform-specific properties and callbacks + /// available on the [platformDispatcher]. + /// + /// For applications designed for more than one main window, prefer using the + /// [platformDispatcher] to access available views via + /// [ui.PlatformDispatcher.views]. + /// + /// However, multiple window support is not yet implemented, so currently this + /// provides access to the one and only window. + // TODO(gspencergoog): remove the preceding note once multi-window support is + // active. + ui.SingletonFlutterWindow get window => ui.window; + + /// The [ui.PlatformDispatcher] to which this binding is bound. + /// + /// A number of additional bindings are defined as extensions of + /// [BindingBase], e.g., [ServicesBinding], [RendererBinding], and + /// [WidgetsBinding]. Each of these bindings define behaviors that interact + /// with a [ui.PlatformDispatcher], e.g., [ServicesBinding] registers a + /// [ui.PlatformDispatcher.onPlatformMessage] handler, and [RendererBinding] + /// registers [ui.PlatformDispatcher.onMetricsChanged], + /// [ui.PlatformDispatcher.onTextScaleFactorChanged], + /// [ui.PlatformDispatcher.onSemanticsEnabledChanged], and + /// [ui.PlatformDispatcher.onSemanticsAction] handlers. + /// + /// Each of these other bindings could individually access a + /// [ui.PlatformDispatcher] statically, but that would preclude the ability to + /// test these behaviors with a fake platform dispatcher for verification + /// purposes. Therefore, [BindingBase] exposes this [ui.PlatformDispatcher] + /// for use by other bindings. A subclass of [BindingBase], such as /// [TestWidgetsFlutterBinding], can override this accessor to return a - /// different [Window] implementation, such as a [TestWindow]. - ui.Window get window => ui.window; + /// different [ui.PlatformDispatcher] implementation. + ui.PlatformDispatcher get platformDispatcher => ui.PlatformDispatcher.instance; /// The initialization method. Subclasses override this method to hook into /// the platform and otherwise configure their services. Subclasses must call @@ -202,12 +236,12 @@ abstract class BindingBase { } _postExtensionStateChangedEvent( brightnessOverrideExtensionName, - (debugBrightnessOverride ?? window.platformBrightness).toString(), + (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(), ); await reassembleApplication(); } return { - 'value': (debugBrightnessOverride ?? window.platformBrightness).toString(), + 'value': (debugBrightnessOverride ?? platformDispatcher.platformBrightness).toString(), }; }, ); diff --git a/packages/flutter/lib/src/foundation/debug.dart b/packages/flutter/lib/src/foundation/debug.dart index d0d583800c..daf0af53f5 100644 --- a/packages/flutter/lib/src/foundation/debug.dart +++ b/packages/flutter/lib/src/foundation/debug.dart @@ -102,7 +102,7 @@ String debugFormatDouble(double? value) { } /// A setting that can be used to override the platform [Brightness] exposed -/// from [BindingBase.window]. +/// from [BindingBase.platformDispatcher]. /// /// See also: /// diff --git a/packages/flutter/lib/src/gestures/binding.dart b/packages/flutter/lib/src/gestures/binding.dart index 3eda495ef7..8b42ad053d 100644 --- a/packages/flutter/lib/src/gestures/binding.dart +++ b/packages/flutter/lib/src/gestures/binding.dart @@ -158,7 +158,7 @@ const Duration _samplingInterval = Duration(microseconds: 16667); /// ### [PointerDownEvent] /// /// When a [PointerDownEvent] is received by the [GestureBinding] (from -/// [Window.onPointerDataPacket], as interpreted by the +/// [dart:ui.PlatformDispatcher.onPointerDataPacket], as interpreted by the /// [PointerEventConverter]), a [hitTest] is performed to determine which /// [HitTestTarget] nodes are affected. (Other bindings are expected to /// implement [hitTest] to defer to [HitTestable] objects. For example, the @@ -198,7 +198,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H void initInstances() { super.initInstances(); _instance = this; - window.onPointerDataPacket = _handlePointerDataPacket; + platformDispatcher.onPointerDataPacket = _handlePointerDataPacket; } @override diff --git a/packages/flutter/lib/src/gestures/converter.dart b/packages/flutter/lib/src/gestures/converter.dart index d79922c3fd..901e7b3b44 100644 --- a/packages/flutter/lib/src/gestures/converter.dart +++ b/packages/flutter/lib/src/gestures/converter.dart @@ -30,8 +30,8 @@ int _synthesiseDownButtons(int buttons, PointerDeviceKind kind) { /// Converts from engine pointer data to framework pointer events. /// /// This takes [PointerDataPacket] objects, as received from the engine via -/// [dart:ui.Window.onPointerDataPacket], and converts them to [PointerEvent] -/// objects. +/// [dart:ui.PlatformDispatcher.onPointerDataPacket], and converts them to +/// [PointerEvent] objects. class PointerEventConverter { // This class is not meant to be instantiated or extended; this constructor // prevents instantiation and extension. @@ -42,7 +42,7 @@ class PointerEventConverter { /// pointer events. /// /// The `devicePixelRatio` argument (usually given the value from - /// [dart:ui.Window.devicePixelRatio]) is used to convert the incoming data + /// [dart:ui.FlutterView.devicePixelRatio]) is used to convert the incoming data /// from physical coordinates to logical pixels. See the discussion at /// [PointerEvent] for more details on the [PointerEvent] coordinate space. static Iterable expand(Iterable data, double devicePixelRatio) sync* { diff --git a/packages/flutter/lib/src/gestures/events.dart b/packages/flutter/lib/src/gestures/events.dart index 0130b343f9..b4a17a67e6 100644 --- a/packages/flutter/lib/src/gestures/events.dart +++ b/packages/flutter/lib/src/gestures/events.dart @@ -229,7 +229,8 @@ bool isSingleButton(int buttons) => buttons != 0 && (smallestButton(buttons) == /// /// See also: /// -/// * [Window.devicePixelRatio], which defines the device's current resolution. +/// * [dart:ui.FlutterView.devicePixelRatio], which defines the device's +/// current resolution. /// * [Listener], a widget that calls callbacks in response to common pointer /// events. @immutable diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart index e38ccc09ad..ac37ebe3d7 100644 --- a/packages/flutter/lib/src/material/app.dart +++ b/packages/flutter/lib/src/material/app.dart @@ -71,7 +71,7 @@ enum ThemeMode { /// If a [Navigator] is created, at least one of these options must handle the /// `/` route, since it is used when an invalid [initialRoute] is specified on /// startup (e.g. by another application launching this one with an intent on -/// Android; see [Window.defaultRouteName]). +/// Android; see [dart:ui.PlatformDispatcher.defaultRouteName]). /// /// This widget also configures the observer of the top-level [Navigator] (if /// any) to perform [Hero] animations. diff --git a/packages/flutter/lib/src/rendering/binding.dart b/packages/flutter/lib/src/rendering/binding.dart index e37afe6672..77d86dbc6b 100644 --- a/packages/flutter/lib/src/rendering/binding.dart +++ b/packages/flutter/lib/src/rendering/binding.dart @@ -33,7 +33,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture onSemanticsOwnerCreated: _handleSemanticsOwnerCreated, onSemanticsOwnerDisposed: _handleSemanticsOwnerDisposed, ); - window + platformDispatcher ..onMetricsChanged = handleMetricsChanged ..onTextScaleFactorChanged = handleTextScaleFactorChanged ..onPlatformBrightnessChanged = handlePlatformBrightnessChanged @@ -187,7 +187,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture /// Called when the system metrics change. /// - /// See [Window.onMetricsChanged]. + /// See [dart:ui.PlatformDispatcher.onMetricsChanged]. @protected void handleMetricsChanged() { assert(renderView != null); @@ -197,7 +197,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture /// Called when the platform text scale factor changes. /// - /// See [Window.onTextScaleFactorChanged]. + /// See [dart:ui.PlatformDispatcher.onTextScaleFactorChanged]. @protected void handleTextScaleFactorChanged() { } @@ -233,7 +233,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture /// ``` /// {@end-tool} /// - /// See [Window.onPlatformBrightnessChanged]. + /// See [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged]. @protected void handlePlatformBrightnessChanged() { } @@ -280,7 +280,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture } void _handleSemanticsEnabledChanged() { - setSemanticsEnabled(window.semanticsEnabled); + setSemanticsEnabled(platformDispatcher.semanticsEnabled); } /// Whether the render tree associated with this binding should produce a tree @@ -414,9 +414,9 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture /// completed this frame. /// /// After [handleBeginFrame], [handleDrawFrame], which is registered with - /// [Window.onDrawFrame], is called, which invokes all the persistent frame - /// callbacks, of which the most notable is this method, [drawFrame], which - /// proceeds as follows: + /// [dart:ui.PlatformDispatcher.onDrawFrame], is called, which invokes all the + /// persistent frame callbacks, of which the most notable is this method, + /// [drawFrame], which proceeds as follows: /// /// 3. The layout phase: All the dirty [RenderObject]s in the system are laid /// out (see [RenderObject.performLayout]). See [RenderObject.markNeedsLayout] diff --git a/packages/flutter/lib/src/rendering/layer.dart b/packages/flutter/lib/src/rendering/layer.dart index c97c878246..478d6249b0 100644 --- a/packages/flutter/lib/src/rendering/layer.dart +++ b/packages/flutter/lib/src/rendering/layer.dart @@ -86,7 +86,7 @@ class AnnotationResult { /// To composite the tree, create a [SceneBuilder] object, pass it to the /// root [Layer] object's [addToScene] method, and then call /// [SceneBuilder.build] to obtain a [Scene]. A [Scene] can then be painted -/// using [Window.render]. +/// using [dart:ui.FlutterView.render]. /// /// See also: /// @@ -1179,9 +1179,9 @@ class OffsetLayer extends ContainerLayer { /// /// The [pixelRatio] describes the scale between the logical pixels and the /// size of the output image. It is independent of the - /// [Window.devicePixelRatio] for the device, so specifying 1.0 (the default) - /// will give you a 1:1 mapping between logical pixels and the output pixels - /// in the image. + /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0 + /// (the default) will give you a 1:1 mapping between logical pixels and the + /// output pixels in the image. /// /// See also: /// diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index 844b1bbd31..c55ed9cd54 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -2914,9 +2914,9 @@ class RenderRepaintBoundary extends RenderProxyBox { /// /// The [pixelRatio] describes the scale between the logical pixels and the /// size of the output image. It is independent of the - /// [Window.devicePixelRatio] for the device, so specifying 1.0 (the default) - /// will give you a 1:1 mapping between logical pixels and the output pixels - /// in the image. + /// [dart:ui.FlutterView.devicePixelRatio] for the device, so specifying 1.0 + /// (the default) will give you a 1:1 mapping between logical pixels and the + /// output pixels in the image. /// /// {@tool snippet} /// diff --git a/packages/flutter/lib/src/rendering/view.dart b/packages/flutter/lib/src/rendering/view.dart index 7dc47d2f96..00733061e4 100644 --- a/packages/flutter/lib/src/rendering/view.dart +++ b/packages/flutter/lib/src/rendering/view.dart @@ -4,7 +4,7 @@ import 'dart:developer'; import 'dart:io' show Platform; -import 'dart:ui' as ui show Scene, SceneBuilder, Window; +import 'dart:ui' as ui show Scene, SceneBuilder, FlutterView; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; @@ -57,7 +57,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin RenderView({ RenderBox? child, required ViewConfiguration configuration, - required ui.Window window, + required ui.FlutterView window, }) : assert(configuration != null), _configuration = configuration, _window = window { @@ -85,7 +85,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin markNeedsLayout(); } - final ui.Window _window; + final ui.FlutterView _window; /// Whether Flutter should automatically compute the desired system UI. /// @@ -334,7 +334,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin properties.add(DiagnosticsProperty('window size', _window.physicalSize, tooltip: 'in physical pixels')); properties.add(DoubleProperty('device pixel ratio', _window.devicePixelRatio, tooltip: 'physical pixels per logical pixel')); properties.add(DiagnosticsProperty('configuration', configuration, tooltip: 'in logical pixels')); - if (_window.semanticsEnabled) + if (_window.platformDispatcher.semanticsEnabled) properties.add(DiagnosticsNode.message('semantics enabled')); } } diff --git a/packages/flutter/lib/src/scheduler/binding.dart b/packages/flutter/lib/src/scheduler/binding.dart index 519d0b50f8..a57ac34dad 100644 --- a/packages/flutter/lib/src/scheduler/binding.dart +++ b/packages/flutter/lib/src/scheduler/binding.dart @@ -5,7 +5,7 @@ import 'dart:async'; import 'dart:collection'; import 'dart:developer' show Flow, Timeline; -import 'dart:ui' show AppLifecycleState, FramePhase, FrameTiming, TimingsCallback; +import 'dart:ui' show AppLifecycleState, FramePhase, FrameTiming, TimingsCallback, PlatformDispatcher; import 'package:collection/collection.dart' show PriorityQueue, HeapPriorityQueue; import 'package:flutter/foundation.dart'; @@ -179,18 +179,18 @@ enum SchedulerPhase { /// Scheduler for running the following: /// -/// * _Transient callbacks_, triggered by the system's [Window.onBeginFrame] -/// callback, for synchronizing the application's behavior to the system's -/// display. For example, [Ticker]s and [AnimationController]s trigger from -/// these. +/// * _Transient callbacks_, triggered by the system's +/// [dart:ui.PlatformDispatcher.onBeginFrame] callback, for synchronizing the +/// application's behavior to the system's display. For example, [Ticker]s and +/// [AnimationController]s trigger from these. /// -/// * _Persistent callbacks_, triggered by the system's [Window.onDrawFrame] -/// callback, for updating the system's display after transient callbacks have -/// executed. For example, the rendering layer uses this to drive its -/// rendering pipeline. +/// * _Persistent callbacks_, triggered by the system's +/// [dart:ui.PlatformDispatcher.onDrawFrame] callback, for updating the +/// system's display after transient callbacks have executed. For example, the +/// rendering layer uses this to drive its rendering pipeline. /// /// * _Post-frame callbacks_, which are run after persistent callbacks, just -/// before returning from the [Window.onDrawFrame] callback. +/// before returning from the [dart:ui.PlatformDispatcher.onDrawFrame] callback. /// /// * Non-rendering tasks, to be run between frames. These are given a /// priority and are executed in priority order according to a @@ -238,20 +238,20 @@ mixin SchedulerBinding on BindingBase { /// feel more sluggish. /// /// Using [addTimingsCallback] is preferred over using - /// [Window.onReportTimings] directly because the - /// [Window.onReportTimings] API only allows one callback, which - /// prevents multiple libraries from registering listeners - /// simultaneously, while this API allows multiple callbacks to be - /// registered independently. + /// [dart:ui.PlatformDispatcher.onReportTimings] directly because the + /// [dart:ui.PlatformDispatcher.onReportTimings] API only allows one callback, + /// which prevents multiple libraries from registering listeners + /// simultaneously, while this API allows multiple callbacks to be registered + /// independently. /// - /// This API is implemented in terms of [Window.onReportTimings]. In - /// release builds, when no libraries have registered with this API, - /// the [Window.onReportTimings] callback is not set, which disables - /// the performance tracking and reduces the runtime overhead to - /// approximately zero. The performance overhead of the performance - /// tracking when one or more callbacks are registered (i.e. when it - /// is enabled) is very approximately 0.01% CPU usage per second - /// (measured on an iPhone 6s). + /// This API is implemented in terms of + /// [dart:ui.PlatformDispatcher.onReportTimings]. In release builds, when no + /// libraries have registered with this API, the + /// [dart:ui.PlatformDispatcher.onReportTimings] callback is not set, which + /// disables the performance tracking and reduces the runtime overhead to + /// approximately zero. The performance overhead of the performance tracking + /// when one or more callbacks are registered (i.e. when it is enabled) is + /// very approximately 0.01% CPU usage per second (measured on an iPhone 6s). /// /// In debug and profile builds, the [SchedulerBinding] itself /// registers a timings callback to update the [Timeline]. @@ -265,10 +265,10 @@ mixin SchedulerBinding on BindingBase { void addTimingsCallback(TimingsCallback callback) { _timingsCallbacks.add(callback); if (_timingsCallbacks.length == 1) { - assert(window.onReportTimings == null); - window.onReportTimings = _executeTimingsCallbacks; + assert(platformDispatcher.onReportTimings == null); + platformDispatcher.onReportTimings = _executeTimingsCallbacks; } - assert(window.onReportTimings == _executeTimingsCallbacks); + assert(platformDispatcher.onReportTimings == _executeTimingsCallbacks); } /// Removes a callback that was earlier added by [addTimingsCallback]. @@ -276,7 +276,7 @@ mixin SchedulerBinding on BindingBase { assert(_timingsCallbacks.contains(callback)); _timingsCallbacks.remove(callback); if (_timingsCallbacks.isEmpty) { - window.onReportTimings = null; + platformDispatcher.onReportTimings = null; } } @@ -720,12 +720,12 @@ mixin SchedulerBinding on BindingBase { scheduleFrame(); } - /// Ensures callbacks for `window.onBeginFrame` and `window.onDrawFrame` - /// are registered. + /// Ensures callbacks for [PlatformDispatcher.onBeginFrame] and + /// [PlatformDispatcher.onDrawFrame] are registered. @protected void ensureFrameCallbacksRegistered() { - window.onBeginFrame ??= _handleBeginFrame; - window.onDrawFrame ??= _handleDrawFrame; + platformDispatcher.onBeginFrame ??= _handleBeginFrame; + platformDispatcher.onDrawFrame ??= _handleDrawFrame; } /// Schedules a new frame using [scheduleFrame] if this object is not @@ -755,7 +755,7 @@ mixin SchedulerBinding on BindingBase { } /// If necessary, schedules a new frame by calling - /// [Window.scheduleFrame]. + /// [dart:ui.PlatformDispatcher.scheduleFrame]. /// /// After this is called, the engine will (eventually) call /// [handleBeginFrame]. (This call might be delayed, e.g. if the device's @@ -790,11 +790,12 @@ mixin SchedulerBinding on BindingBase { return true; }()); ensureFrameCallbacksRegistered(); - window.scheduleFrame(); + platformDispatcher.scheduleFrame(); _hasScheduledFrame = true; } - /// Schedules a new frame by calling [Window.scheduleFrame]. + /// Schedules a new frame by calling + /// [dart:ui.PlatformDispatcher.scheduleFrame]. /// /// After this is called, the engine will call [handleBeginFrame], even if /// frames would normally not be scheduled by [scheduleFrame] (e.g. even if @@ -826,7 +827,7 @@ mixin SchedulerBinding on BindingBase { debugPrintStack(label: 'scheduleForcedFrame() called. Current phase is $schedulerPhase.'); return true; }()); - window.scheduleFrame(); + platformDispatcher.scheduleFrame(); _hasScheduledFrame = true; } @@ -934,8 +935,9 @@ mixin SchedulerBinding on BindingBase { } Duration? _currentFrameTimeStamp; - /// The raw time stamp as provided by the engine to [Window.onBeginFrame] - /// for the frame currently being processed. + /// The raw time stamp as provided by the engine to + /// [dart:ui.PlatformDispatcher.onBeginFrame] for the frame currently being + /// processed. /// /// Unlike [currentFrameTimeStamp], this time stamp is neither adjusted to /// offset when the epoch started nor scaled to reflect the [timeDilation] in diff --git a/packages/flutter/lib/src/semantics/binding.dart b/packages/flutter/lib/src/semantics/binding.dart index 4a6ed1f2d1..62f9b82b06 100644 --- a/packages/flutter/lib/src/semantics/binding.dart +++ b/packages/flutter/lib/src/semantics/binding.dart @@ -21,15 +21,15 @@ mixin SemanticsBinding on BindingBase { void initInstances() { super.initInstances(); _instance = this; - _accessibilityFeatures = window.accessibilityFeatures; + _accessibilityFeatures = platformDispatcher.accessibilityFeatures; } /// Called when the platform accessibility features change. /// - /// See [Window.onAccessibilityFeaturesChanged]. + /// See [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged]. @protected void handleAccessibilityFeaturesChanged() { - _accessibilityFeatures = window.accessibilityFeatures; + _accessibilityFeatures = platformDispatcher.accessibilityFeatures; } /// Creates an empty semantics update builder. diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart index 4665ed064f..d30d1d7e87 100644 --- a/packages/flutter/lib/src/semantics/semantics.dart +++ b/packages/flutter/lib/src/semantics/semantics.dart @@ -2611,7 +2611,7 @@ class SemanticsOwner extends ChangeNotifier { super.dispose(); } - /// Update the semantics using [Window.updateSemantics]. + /// Update the semantics using [dart:ui.PlatformDispatcher.updateSemantics]. void sendSemanticsUpdate() { if (_dirtyNodes.isEmpty) return; @@ -2658,7 +2658,7 @@ class SemanticsOwner extends ChangeNotifier { final CustomSemanticsAction action = CustomSemanticsAction.getAction(actionId)!; builder.updateCustomAction(id: actionId, label: action.label, hint: action.hint, overrideId: action.action?.index ?? -1); } - SemanticsBinding.instance!.window.updateSemantics(builder.build()); + SemanticsBinding.instance!.platformDispatcher.updateSemantics(builder.build()); notifyListeners(); } diff --git a/packages/flutter/lib/src/services/binary_messenger.dart b/packages/flutter/lib/src/services/binary_messenger.dart index 4b27557d01..7589b2b96e 100644 --- a/packages/flutter/lib/src/services/binary_messenger.dart +++ b/packages/flutter/lib/src/services/binary_messenger.dart @@ -22,7 +22,7 @@ abstract class BinaryMessenger { /// Calls the handler registered for the given channel. /// /// Typically called by [ServicesBinding] to handle platform messages received - /// from [Window.onPlatformMessage]. + /// from [dart:ui.PlatformDispatcher.onPlatformMessage]. /// /// To register a handler for a given message channel, see [setMessageHandler]. Future handlePlatformMessage(String channel, ByteData? data, ui.PlatformMessageResponseCallback? callback); diff --git a/packages/flutter/lib/src/services/binding.dart b/packages/flutter/lib/src/services/binding.dart index a4a4aeca6b..b4fa2c8e6c 100644 --- a/packages/flutter/lib/src/services/binding.dart +++ b/packages/flutter/lib/src/services/binding.dart @@ -28,7 +28,7 @@ mixin ServicesBinding on BindingBase, SchedulerBinding { _instance = this; _defaultBinaryMessenger = createBinaryMessenger(); _restorationManager = createRestorationManager(); - window.onPlatformMessage = defaultBinaryMessenger.handlePlatformMessage; + platformDispatcher.onPlatformMessage = defaultBinaryMessenger.handlePlatformMessage; initLicenses(); SystemChannels.system.setMessageHandler((dynamic message) => handleSystemMessage(message as Object)); SystemChannels.lifecycle.setMessageHandler(_handleLifecycleMessage); @@ -166,14 +166,14 @@ mixin ServicesBinding on BindingBase, SchedulerBinding { // App life cycle - /// Initializes the [lifecycleState] with the [Window.initialLifecycleState] - /// from the window. + /// Initializes the [lifecycleState] with the + /// [dart:ui.SingletonFlutterWindow.initialLifecycleState]. /// /// Once the [lifecycleState] is populated through any means (including this /// method), this method will do nothing. This is because the - /// [Window.initialLifecycleState] may already be stale and it no longer makes - /// sense to use the initial state at dart vm startup as the current state - /// anymore. + /// [dart:ui.SingletonFlutterWindow.initialLifecycleState] may already be + /// stale and it no longer makes sense to use the initial state at dart vm + /// startup as the current state anymore. /// /// The latest state should be obtained by subscribing to /// [WidgetsBindingObserver.didChangeAppLifecycleState]. @@ -249,13 +249,14 @@ class _DefaultBinaryMessenger extends BinaryMessenger { Future _sendPlatformMessage(String channel, ByteData? message) { final Completer completer = Completer(); - // ui.window is accessed directly instead of using ServicesBinding.instance.window - // because this method might be invoked before any binding is initialized. - // This issue was reported in #27541. It is not ideal to statically access - // ui.window because the Window may be dependency injected elsewhere with - // a different instance. However, static access at this location seems to be - // the least bad option. - ui.window.sendPlatformMessage(channel, message, (ByteData? reply) { + // ui.PlatformDispatcher.instance is accessed directly instead of using + // ServicesBinding.instance.platformDispatcher because this method might be + // invoked before any binding is initialized. This issue was reported in + // #27541. It is not ideal to statically access + // ui.PlatformDispatcher.instance because the PlatformDispatcher may be + // dependency injected elsewhere with a different instance. However, static + // access at this location seems to be the least bad option. + ui.PlatformDispatcher.instance.sendPlatformMessage(channel, message, (ByteData? reply) { try { completer.complete(reply); } catch (exception, stack) { diff --git a/packages/flutter/lib/src/services/platform_messages.dart b/packages/flutter/lib/src/services/platform_messages.dart index 96e2a9b0a6..813309a562 100644 --- a/packages/flutter/lib/src/services/platform_messages.dart +++ b/packages/flutter/lib/src/services/platform_messages.dart @@ -42,7 +42,7 @@ class BinaryMessages { /// Calls the handler registered for the given channel. /// /// Typically called by [ServicesBinding] to handle platform messages received - /// from [Window.onPlatformMessage]. + /// from [dart:ui.PlatformDispatcher.onPlatformMessage]. /// /// To register a handler for a given message channel, see [setMessageHandler]. @Deprecated( diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index c8cbb0971a..1a14c9c56d 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -433,8 +433,8 @@ class WidgetsApp extends StatefulWidget { /// This object will be used by the underlying [Router]. /// /// If this is not provided, the widgets app will create a - /// [PlatformRouteInformationProvider] with initial route name equals to - /// the [Window.defaultRouteName] by default. + /// [PlatformRouteInformationProvider] with initial route name equal to the + /// [dart:ui.PlatformDispatcher.defaultRouteName] by default. /// /// See also: /// @@ -525,8 +525,8 @@ class WidgetsApp extends StatefulWidget { /// {@template flutter.widgets.widgetsApp.initialRoute} /// The name of the first route to show, if a [Navigator] is built. /// - /// Defaults to [Window.defaultRouteName], which may be overridden by the code - /// that launched the application. + /// Defaults to [dart:ui.PlatformDispatcher.defaultRouteName], which may be + /// overridden by the code that launched the application. /// /// If the route name starts with a slash, then it is treated as a "deep link", /// and before this route is pushed, the routes leading to this one are pushed @@ -1113,15 +1113,15 @@ class _WidgetsAppState extends State with WidgetsBindingObserver { // If window.defaultRouteName isn't '/', we should assume it was set // intentionally via `setInitialRoute`, and should override whatever is in // [widget.initialRoute]. - String get _initialRouteName => WidgetsBinding.instance!.window.defaultRouteName != Navigator.defaultRouteName - ? WidgetsBinding.instance!.window.defaultRouteName - : widget.initialRoute ?? WidgetsBinding.instance!.window.defaultRouteName; + String get _initialRouteName => WidgetsBinding.instance!.platformDispatcher.defaultRouteName != Navigator.defaultRouteName + ? WidgetsBinding.instance!.platformDispatcher.defaultRouteName + : widget.initialRoute ?? WidgetsBinding.instance!.platformDispatcher.defaultRouteName; @override void initState() { super.initState(); _updateRouting(); - _locale = _resolveLocales(WidgetsBinding.instance!.window.locales, widget.supportedLocales); + _locale = _resolveLocales(WidgetsBinding.instance!.platformDispatcher.locales, widget.supportedLocales); WidgetsBinding.instance!.addObserver(this); } diff --git a/packages/flutter/lib/src/widgets/binding.dart b/packages/flutter/lib/src/widgets/binding.dart index 95782338dd..22c4e085f7 100644 --- a/packages/flutter/lib/src/widgets/binding.dart +++ b/packages/flutter/lib/src/widgets/binding.dart @@ -4,7 +4,7 @@ import 'dart:async'; import 'dart:developer' as developer; -import 'dart:ui' show AppLifecycleState, Locale, AccessibilityFeatures, FrameTiming, TimingsCallback; +import 'dart:ui' show AppLifecycleState, Locale, AccessibilityFeatures, FrameTiming, TimingsCallback, PlatformDispatcher; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; @@ -124,7 +124,8 @@ abstract class WidgetsBindingObserver { /// Called when the application's dimensions change. For example, /// when a phone is rotated. /// - /// This method exposes notifications from [Window.onMetricsChanged]. + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onMetricsChanged]. /// /// {@tool snippet} /// @@ -185,7 +186,8 @@ abstract class WidgetsBindingObserver { /// preferences, and it should affect all of the text sizes in the /// application. /// - /// This method exposes notifications from [Window.onTextScaleFactorChanged]. + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onTextScaleFactorChanged]. /// /// {@tool snippet} /// @@ -233,14 +235,16 @@ abstract class WidgetsBindingObserver { /// Called when the platform brightness changes. /// - /// This method exposes notifications from [Window.onPlatformBrightnessChanged]. + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onPlatformBrightnessChanged]. void didChangePlatformBrightness() { } /// Called when the system tells the app that the user's locale has /// changed. For example, if the user changes the system language /// settings. /// - /// This method exposes notifications from [Window.onLocaleChanged]. + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onLocaleChanged]. void didChangeLocales(List? locale) { } /// Called when the system puts the app in the background or returns @@ -261,7 +265,8 @@ abstract class WidgetsBindingObserver { /// Called when the system changes the set of currently active accessibility /// features. /// - /// This method exposes notifications from [Window.onAccessibilityFeaturesChanged]. + /// This method exposes notifications from + /// [dart:ui.PlatformDispatcher.onAccessibilityFeaturesChanged]. void didChangeAccessibilityFeatures() { } } @@ -282,8 +287,8 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB // properly setup the [defaultBinaryMessenger] instance. _buildOwner = BuildOwner(); buildOwner!.onBuildScheduled = _handleBuildScheduled; - window.onLocaleChanged = handleLocaleChanged; - window.onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged; + platformDispatcher.onLocaleChanged = handleLocaleChanged; + platformDispatcher.onAccessibilityFeaturesChanged = handleAccessibilityFeaturesChanged; SystemChannels.navigation.setMethodCallHandler(_handleNavigationInvocation); FlutterErrorDetails.propertiesTransformers.add(transformDebugCreator); } @@ -577,19 +582,19 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB /// /// Calls [dispatchLocalesChanged] to notify the binding observers. /// - /// See [Window.onLocaleChanged]. + /// See [dart:ui.PlatformDispatcher.onLocaleChanged]. @protected @mustCallSuper void handleLocaleChanged() { - dispatchLocalesChanged(window.locales); + dispatchLocalesChanged(platformDispatcher.locales); } /// Notify all the observers that the locale has changed (using /// [WidgetsBindingObserver.didChangeLocales]), giving them the /// `locales` argument. /// - /// This is called by [handleLocaleChanged] when the [Window.onLocaleChanged] - /// notification is received. + /// This is called by [handleLocaleChanged] when the + /// [PlatformDispatcher.onLocaleChanged] notification is received. @protected @mustCallSuper void dispatchLocalesChanged(List? locales) { @@ -602,7 +607,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB /// giving them the `features` argument. /// /// This is called by [handleAccessibilityFeaturesChanged] when the - /// [Window.onAccessibilityFeaturesChanged] notification is received. + /// [PlatformDispatcher.onAccessibilityFeaturesChanged] notification is received. @protected @mustCallSuper void dispatchAccessibilityFeaturesChanged() { @@ -806,11 +811,11 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB /// Each frame consists of the following phases: /// /// 1. The animation phase: The [handleBeginFrame] method, which is registered - /// with [Window.onBeginFrame], invokes all the transient frame callbacks - /// registered with [scheduleFrameCallback], in - /// registration order. This includes all the [Ticker] instances that are - /// driving [AnimationController] objects, which means all of the active - /// [Animation] objects tick at this point. + /// with [PlatformDispatcher.onBeginFrame], invokes all the transient frame + /// callbacks registered with [scheduleFrameCallback], in registration order. + /// This includes all the [Ticker] instances that are driving + /// [AnimationController] objects, which means all of the active [Animation] + /// objects tick at this point. /// /// 2. Microtasks: After [handleBeginFrame] returns, any microtasks that got /// scheduled by transient frame callbacks get to run. This typically includes @@ -818,9 +823,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB /// completed this frame. /// /// After [handleBeginFrame], [handleDrawFrame], which is registered with - /// [Window.onDrawFrame], is called, which invokes all the persistent frame - /// callbacks, of which the most notable is this method, [drawFrame], which - /// proceeds as follows: + /// [PlatformDispatcher.onDrawFrame], is called, which invokes all the + /// persistent frame callbacks, of which the most notable is this method, + /// [drawFrame], which proceeds as follows: /// /// 3. The build phase: All the dirty [Element]s in the widget tree are /// rebuilt (see [State.build]). See [State.setState] for further details on @@ -883,9 +888,9 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB firstFrameCallback = null; _firstFrameCompleter.complete(); }; - // Callback is only invoked when [Window.render] is called. When - // [sendFramesToEngine] is set to false during the frame, it will not - // be called and we need to remove the callback (see below). + // Callback is only invoked when FlutterView.render is called. When + // sendFramesToEngine is set to false during the frame, it will not be + // called and we need to remove the callback (see below). SchedulerBinding.instance!.addTimingsCallback(firstFrameCallback!); } @@ -1011,7 +1016,7 @@ mixin WidgetsBinding on BindingBase, ServicesBinding, SchedulerBinding, GestureB /// method again with the matched locale of the first call omitted from /// `supportedLocales`. Locale? computePlatformResolvedLocale(List supportedLocales) { - return window.computePlatformResolvedLocale(supportedLocales); + return platformDispatcher.computePlatformResolvedLocale(supportedLocales); } } diff --git a/packages/flutter/lib/src/widgets/media_query.dart b/packages/flutter/lib/src/widgets/media_query.dart index cf1cbb901b..39fa1c111e 100644 --- a/packages/flutter/lib/src/widgets/media_query.dart +++ b/packages/flutter/lib/src/widgets/media_query.dart @@ -86,7 +86,7 @@ class MediaQueryData { /// Creates data for a media query with explicit values. /// /// Consider using [MediaQueryData.fromWindow] to create data based on a - /// [Window]. + /// [dart:ui.PlatformDispatcher]. const MediaQueryData({ this.size = Size.zero, this.devicePixelRatio = 1.0, @@ -124,8 +124,9 @@ class MediaQueryData { /// If you use this, you should ensure that you also register for /// notifications so that you can update your [MediaQueryData] when the /// window's metrics change. For example, see - /// [WidgetsBindingObserver.didChangeMetrics] or [Window.onMetricsChanged]. - MediaQueryData.fromWindow(ui.Window window) + /// [WidgetsBindingObserver.didChangeMetrics] or + /// [dart:ui.PlatformDispatcher.onMetricsChanged]. + MediaQueryData.fromWindow(ui.SingletonFlutterWindow window) : size = window.physicalSize / window.devicePixelRatio, devicePixelRatio = window.devicePixelRatio, textScaleFactor = window.textScaleFactor, @@ -308,7 +309,7 @@ class MediaQueryData { /// /// See also: /// - /// * [Window.accessibilityFeatures], where the setting originates. + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting originates. final bool accessibleNavigation; /// Whether the device is inverting the colors of the platform. @@ -317,7 +318,8 @@ class MediaQueryData { /// /// See also: /// - /// * [Window.accessibilityFeatures], where the setting originates. + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting + /// originates. final bool invertColors; /// Whether the user requested a high contrast between foreground and background @@ -332,7 +334,8 @@ class MediaQueryData { /// /// See also: /// - /// * [Window.accessibilityFeatures], where the setting originates. + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting + /// originates. final bool disableAnimations; /// Whether the platform is requesting that text be drawn with a bold font @@ -340,7 +343,8 @@ class MediaQueryData { /// /// See also: /// - /// * [Window.accessibilityFeatures], where the setting originates. + /// * [dart:ui.PlatformDispatcher.accessibilityFeatures], where the setting + /// originates. final bool boldText; /// Describes the navigation mode requested by the platform. diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index c95399f27f..45a7ce093b 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -1563,7 +1563,7 @@ class Navigator extends StatefulWidget { /// /// See also: /// - /// * [dart:ui.Window.defaultRouteName], which reflects the route that the + /// * [dart:ui.PlatformDispatcher.defaultRouteName], which reflects the route that the /// application was started with. static const String defaultRouteName = '/'; diff --git a/packages/flutter/lib/src/widgets/safe_area.dart b/packages/flutter/lib/src/widgets/safe_area.dart index 7d23589c98..cf74e01c88 100644 --- a/packages/flutter/lib/src/widgets/safe_area.dart +++ b/packages/flutter/lib/src/widgets/safe_area.dart @@ -31,7 +31,7 @@ import 'media_query.dart'; /// intrusions. /// * [Padding], for insetting widgets in general. /// * [MediaQuery], from which the window padding is obtained. -/// * [dart:ui.Window.padding], which reports the padding from the operating +/// * [dart:ui.FlutterView.padding], which reports the padding from the operating /// system. class SafeArea extends StatelessWidget { /// Creates a widget that avoids operating system interfaces. @@ -147,7 +147,7 @@ class SafeArea extends StatelessWidget { /// * [SafeArea], for insetting widgets to avoid operating system intrusions. /// * [SliverPadding], for insetting slivers in general. /// * [MediaQuery], from which the window padding is obtained. -/// * [dart:ui.Window.padding], which reports the padding from the operating +/// * [dart:ui.FlutterView.padding], which reports the padding from the operating /// system. class SliverSafeArea extends StatelessWidget { /// Creates a sliver that avoids operating system interfaces. diff --git a/packages/flutter/test/painting/binding_test.dart b/packages/flutter/test/painting/binding_test.dart index 0ec864d320..0bec915742 100644 --- a/packages/flutter/test/painting/binding_test.dart +++ b/packages/flutter/test/painting/binding_test.dart @@ -87,7 +87,10 @@ class TestBindingBase implements BindingBase { void unlocked() {} @override - ui.Window get window => throw UnimplementedError(); + ui.SingletonFlutterWindow get window => throw UnimplementedError(); + + @override + ui.PlatformDispatcher get platformDispatcher => throw UnimplementedError(); } class TestPaintingBinding extends TestBindingBase with SchedulerBinding, ServicesBinding, PaintingBinding { diff --git a/packages/flutter/test/painting/image_cache_binding_test.dart b/packages/flutter/test/painting/image_cache_binding_test.dart index 4ca25b0f38..f6b228ff48 100644 --- a/packages/flutter/test/painting/image_cache_binding_test.dart +++ b/packages/flutter/test/painting/image_cache_binding_test.dart @@ -71,7 +71,10 @@ class TestBindingBase implements BindingBase { void unlocked() {} @override - ui.Window get window => TestWindow(window: ui.window); + ui.SingletonFlutterWindow get window => TestWindow(window: ui.window); + + @override + ui.PlatformDispatcher get platformDispatcher => TestWindow(window: ui.window).platformDispatcher; } class TestPaintingBinding extends TestBindingBase with SchedulerBinding, ServicesBinding, PaintingBinding {} diff --git a/packages/flutter/test/widgets/binding_first_frame_rasterized_test.dart b/packages/flutter/test/widgets/binding_first_frame_rasterized_test.dart index cb179de46f..45eda8f889 100644 --- a/packages/flutter/test/widgets/binding_first_frame_rasterized_test.dart +++ b/packages/flutter/test/widgets/binding_first_frame_rasterized_test.dart @@ -19,14 +19,14 @@ void main() { // Simulates the engine completing a frame render to trigger the // appropriate callback setting [WidgetBinding.firstFrameRasterized]. - binding.window.onReportTimings!([]); + binding.platformDispatcher.onReportTimings!([]); expect(binding.firstFrameRasterized, isFalse); binding.allowFirstFrame(); fakeAsync.flushTimers(); // Simulates the engine again. - binding.window.onReportTimings!([]); + binding.platformDispatcher.onReportTimings!([]); expect(binding.firstFrameRasterized, isTrue); }); }); diff --git a/packages/flutter/test/widgets/semantics_tester.dart b/packages/flutter/test/widgets/semantics_tester.dart index dfeb623456..570f4adcbf 100644 --- a/packages/flutter/test/widgets/semantics_tester.dart +++ b/packages/flutter/test/widgets/semantics_tester.dart @@ -98,7 +98,8 @@ class TestSemantics { /// set to the appropriate values for direct children of the root node. /// /// The [transform] is set to a 3.0 scale (to account for the - /// [Window.devicePixelRatio] being 3.0 on the test pseudo-device). + /// [dart:ui.FlutterView.devicePixelRatio] being 3.0 on the test + /// pseudo-device). /// /// The [rect] field is required and has no default. The /// [TestSemantics.fullScreen] property may be useful as a value; it describes diff --git a/packages/flutter_driver/lib/src/common/geometry.dart b/packages/flutter_driver/lib/src/common/geometry.dart index aafcd0600d..0fb35aa377 100644 --- a/packages/flutter_driver/lib/src/common/geometry.dart +++ b/packages/flutter_driver/lib/src/common/geometry.dart @@ -31,7 +31,7 @@ EnumIndex _offsetTypeIndex = EnumIndex(OffsetType.values /// identified by [finder]. /// /// The requested offset is returned in logical pixels, which can be translated -/// to device pixels via [Window.devicePixelRatio]. +/// to device pixels via [dart:ui.FlutterView.devicePixelRatio]. class GetOffset extends CommandWithTarget { /// The `finder` looks for an element to get its rect. GetOffset(SerializableFinder finder, this.offsetType, { Duration? timeout }) : super(finder, timeout: timeout); @@ -56,7 +56,7 @@ class GetOffset extends CommandWithTarget { /// The result of the [GetOffset] command. /// /// The offset is provided in logical pixels, which can be translated -/// to device pixels via [Window.devicePixelRatio]. +/// to device pixels via [dart:ui.FlutterView.devicePixelRatio]. class GetOffsetResult extends Result { /// Creates a result with the offset defined by [dx] and [dy]. const GetOffsetResult({ this.dx = 0.0, this.dy = 0.0}); @@ -64,13 +64,13 @@ class GetOffsetResult extends Result { /// The x component of the offset in logical pixels. /// /// The value can be translated to device pixels via - /// [Window.devicePixelRatio]. + /// [dart:ui.FlutterView.devicePixelRatio]. final double dx; /// The y component of the offset in logical pixels. /// /// The value can be translated to device pixels via - /// [Window.devicePixelRatio]. + /// [dart:ui.FlutterView.devicePixelRatio]. final double dy; /// Deserializes the result from JSON. diff --git a/packages/flutter_driver/lib/src/driver/driver.dart b/packages/flutter_driver/lib/src/driver/driver.dart index b049ba5c5e..ab5ecb6033 100644 --- a/packages/flutter_driver/lib/src/driver/driver.dart +++ b/packages/flutter_driver/lib/src/driver/driver.dart @@ -227,7 +227,8 @@ abstract class FlutterDriver { await sendCommand(WaitForCondition(const NoTransientCallbacks(), timeout: timeout)); } - /// Waits until the next [Window.onReportTimings] is called. + /// Waits until the next [dart:ui.PlatformDispatcher.onReportTimings] is + /// called. /// /// Use this method to wait for the first frame to be rasterized during the /// app launch. @@ -246,7 +247,7 @@ abstract class FlutterDriver { /// Returns the point at the top left of the widget identified by `finder`. /// /// The offset is expressed in logical pixels and can be translated to - /// device pixels via [Window.devicePixelRatio]. + /// device pixels via [dart:ui.FlutterView.devicePixelRatio]. Future getTopLeft(SerializableFinder finder, { Duration timeout }) async { return _getOffset(finder, OffsetType.topLeft, timeout: timeout); } @@ -254,7 +255,7 @@ abstract class FlutterDriver { /// Returns the point at the top right of the widget identified by `finder`. /// /// The offset is expressed in logical pixels and can be translated to - /// device pixels via [Window.devicePixelRatio]. + /// device pixels via [dart:ui.FlutterView.devicePixelRatio]. Future getTopRight(SerializableFinder finder, { Duration timeout }) async { return _getOffset(finder, OffsetType.topRight, timeout: timeout); } @@ -262,7 +263,7 @@ abstract class FlutterDriver { /// Returns the point at the bottom left of the widget identified by `finder`. /// /// The offset is expressed in logical pixels and can be translated to - /// device pixels via [Window.devicePixelRatio]. + /// device pixels via [dart:ui.FlutterView.devicePixelRatio]. Future getBottomLeft(SerializableFinder finder, { Duration timeout }) async { return _getOffset(finder, OffsetType.bottomLeft, timeout: timeout); } @@ -270,7 +271,7 @@ abstract class FlutterDriver { /// Returns the point at the bottom right of the widget identified by `finder`. /// /// The offset is expressed in logical pixels and can be translated to - /// device pixels via [Window.devicePixelRatio]. + /// device pixels via [dart:ui.FlutterView.devicePixelRatio]. Future getBottomRight(SerializableFinder finder, { Duration timeout }) async { return _getOffset(finder, OffsetType.bottomRight, timeout: timeout); } @@ -278,7 +279,7 @@ abstract class FlutterDriver { /// Returns the point at the center of the widget identified by `finder`. /// /// The offset is expressed in logical pixels and can be translated to - /// device pixels via [Window.devicePixelRatio]. + /// device pixels via [dart:ui.FlutterView.devicePixelRatio]. Future getCenter(SerializableFinder finder, { Duration timeout }) async { return _getOffset(finder, OffsetType.center, timeout: timeout); } diff --git a/packages/flutter_test/lib/src/_matchers_web.dart b/packages/flutter_test/lib/src/_matchers_web.dart index c8107b32b0..e87c9c0901 100644 --- a/packages/flutter_test/lib/src/_matchers_web.dart +++ b/packages/flutter_test/lib/src/_matchers_web.dart @@ -88,7 +88,7 @@ RenderObject _findRepaintBoundary(Element element) { return renderObject; } -void _renderElement(ui.Window window, RenderObject renderObject) { +void _renderElement(ui.FlutterView window, RenderObject renderObject) { assert(renderObject.debugLayer != null); final Layer layer = renderObject.debugLayer!; final ui.SceneBuilder sceneBuilder = ui.SceneBuilder(); diff --git a/packages/flutter_test/lib/src/accessibility.dart b/packages/flutter_test/lib/src/accessibility.dart index 59171e2222..a8fd86dc4e 100644 --- a/packages/flutter_test/lib/src/accessibility.dart +++ b/packages/flutter_test/lib/src/accessibility.dart @@ -311,7 +311,7 @@ class MinimumTextContrastGuideline extends AccessibilityGuideline { // Given a pixel buffer based on the physical window size, can we actually // get all the data from this node? allow a small delta overlap before // culling the node. - bool _isNodeOffScreen(Rect paintBounds, ui.Window window) { + bool _isNodeOffScreen(Rect paintBounds, ui.FlutterView window) { return paintBounds.top < -50.0 || paintBounds.left < -50.0 || paintBounds.bottom > (window.physicalSize.height * window.devicePixelRatio) + 50.0 diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index c645c3f06b..d1714f07dc 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -1038,9 +1038,9 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { @override void ensureFrameCallbacksRegistered() { - // Leave Window alone, do nothing. - assert(window.onDrawFrame == null); - assert(window.onBeginFrame == null); + // Leave PlatformDispatcher alone, do nothing. + assert(platformDispatcher.onDrawFrame == null); + assert(platformDispatcher.onBeginFrame == null); } @override @@ -1326,7 +1326,7 @@ enum LiveTestWidgetsFlutterBindingFramePolicy { /// pipeline directly. It tells the binding to entirely ignore requests for a /// frame to be scheduled, while still allowing frames that are pumped /// directly to run (either by using [WidgetTester.pumpBenchmark] or invoking - /// [Window.onBeginFrame] and [Window.onDrawFrame]). + /// [PlatformDispatcher.onBeginFrame] and [PlatformDispatcher.onDrawFrame]). /// /// This allows all frame requests from the engine to be serviced, and allows /// all frame requests that are artificially triggered to be serviced, but @@ -1684,17 +1684,17 @@ class TestViewConfiguration extends ViewConfiguration { /// If a [window] instance is not provided it defaults to [ui.window]. factory TestViewConfiguration({ Size size = _kDefaultTestViewportSize, - ui.Window? window, + ui.FlutterView? window, }) { return TestViewConfiguration._(size, window ?? ui.window); } - TestViewConfiguration._(Size size, ui.Window window) + TestViewConfiguration._(Size size, ui.FlutterView window) : _paintMatrix = _getMatrix(size, window.devicePixelRatio, window), _hitTestMatrix = _getMatrix(size, 1.0, window), super(size: size); - static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.Window window) { + static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) { final double inverseRatio = devicePixelRatio / window.devicePixelRatio; final double actualWidth = window.physicalSize.width * inverseRatio; final double actualHeight = window.physicalSize.height * inverseRatio; @@ -1756,7 +1756,7 @@ class _LiveTestRenderView extends RenderView { _LiveTestRenderView({ required ViewConfiguration configuration, required this.onNeedPaint, - required ui.Window window, + required ui.FlutterView window, }) : super(configuration: configuration, window: window); @override diff --git a/packages/flutter_test/lib/src/window.dart b/packages/flutter_test/lib/src/window.dart index 5250bfc3ac..c946ef851f 100644 --- a/packages/flutter_test/lib/src/window.dart +++ b/packages/flutter_test/lib/src/window.dart @@ -3,16 +3,17 @@ // found in the LICENSE file. import 'dart:typed_data' show ByteData; -import 'dart:ui' hide window; +import 'dart:ui' as ui hide window; -/// [Window] that wraps another [Window] and allows faking of some properties -/// for testing purposes. +/// [SingletonFlutterWindow] that wraps another [SingletonFlutterWindow] and +/// allows faking of some properties for testing purposes. /// /// Tests for certain widgets, e.g., [MaterialApp], might require faking certain -/// properties of a [Window]. [TestWindow] facilitates the faking of these -/// properties by overriding the properties of a real [Window] with desired fake -/// values. The binding used within tests, [TestWidgetsFlutterBinding], contains -/// a [TestWindow] that is used by all tests. +/// properties of a [SingletonFlutterWindow]. [TestWindow] facilitates the +/// faking of these properties by overriding the properties of a real +/// [SingletonFlutterWindow] with desired fake values. The binding used within +/// tests, [TestWidgetsFlutterBinding], contains a [TestWindow] that is used by +/// all tests. /// /// ## Sample Code /// @@ -36,21 +37,22 @@ import 'dart:ui' hide window; /// therefore any fake values defined in one test will not persist /// to the next. /// -/// If a test needs to override a real [Window] property and then later -/// return to using the real [Window] property, [TestWindow] provides -/// methods to clear each individual test value, e.g., [clearLocaleTestValue()]. +/// If a test needs to override a real [SingletonFlutterWindow] property and +/// then later return to using the real [SingletonFlutterWindow] property, +/// [TestWindow] provides methods to clear each individual test value, e.g., +/// [clearLocaleTestValue()]. /// /// To clear all fake test values in a [TestWindow], consider using /// [clearAllTestValues()]. -class TestWindow implements Window { - /// Constructs a [TestWindow] that defers all behavior to the given [Window] - /// unless explicitly overridden for test purposes. +class TestWindow implements ui.SingletonFlutterWindow { + /// Constructs a [TestWindow] that defers all behavior to the given + /// [dart:ui.SingletonFlutterWindow] unless explicitly overridden for test purposes. TestWindow({ - required Window window, + required ui.SingletonFlutterWindow window, }) : _window = window; - /// The [Window] that is wrapped by this [TestWindow]. - final Window _window; + /// The [dart:ui.SingletonFlutterWindow] that is wrapped by this [TestWindow]. + final ui.SingletonFlutterWindow _window; @override double get devicePixelRatio => _devicePixelRatio ?? _window.devicePixelRatio; @@ -69,11 +71,11 @@ class TestWindow implements Window { } @override - Size get physicalSize => _physicalSizeTestValue ?? _window.physicalSize; - Size? _physicalSizeTestValue; + ui.Size get physicalSize => _physicalSizeTestValue ?? _window.physicalSize; + ui.Size? _physicalSizeTestValue; /// Hides the real physical size and reports the given [physicalSizeTestValue] /// instead. - set physicalSizeTestValue (Size physicalSizeTestValue) { + set physicalSizeTestValue (ui.Size physicalSizeTestValue) { _physicalSizeTestValue = physicalSizeTestValue; onMetricsChanged?.call(); } @@ -85,11 +87,11 @@ class TestWindow implements Window { } @override - WindowPadding get viewInsets => _viewInsetsTestValue ?? _window.viewInsets; - WindowPadding? _viewInsetsTestValue; + ui.WindowPadding get viewInsets => _viewInsetsTestValue ?? _window.viewInsets; + ui.WindowPadding? _viewInsetsTestValue; /// Hides the real view insets and reports the given [viewInsetsTestValue] /// instead. - set viewInsetsTestValue(WindowPadding viewInsetsTestValue) { + set viewInsetsTestValue(ui.WindowPadding viewInsetsTestValue) { _viewInsetsTestValue = viewInsetsTestValue; onMetricsChanged?.call(); } @@ -101,11 +103,11 @@ class TestWindow implements Window { } @override - WindowPadding get viewPadding => _viewPaddingTestValue ?? _window.padding; - WindowPadding? _viewPaddingTestValue; + ui.WindowPadding get viewPadding => _viewPaddingTestValue ?? _window.padding; + ui.WindowPadding? _viewPaddingTestValue; /// Hides the real view padding and reports the given [paddingTestValue] /// instead. - set viewPaddingTestValue(WindowPadding viewPaddingTestValue) { + set viewPaddingTestValue(ui.WindowPadding viewPaddingTestValue) { _viewPaddingTestValue = viewPaddingTestValue; onMetricsChanged?.call(); } @@ -117,10 +119,10 @@ class TestWindow implements Window { } @override - WindowPadding get padding => _paddingTestValue ?? _window.padding; - WindowPadding? _paddingTestValue; + ui.WindowPadding get padding => _paddingTestValue ?? _window.padding; + ui.WindowPadding? _paddingTestValue; /// Hides the real padding and reports the given [paddingTestValue] instead. - set paddingTestValue(WindowPadding paddingTestValue) { + set paddingTestValue(ui.WindowPadding paddingTestValue) { _paddingTestValue = paddingTestValue; onMetricsChanged?.call(); } @@ -131,10 +133,10 @@ class TestWindow implements Window { } @override - WindowPadding get systemGestureInsets => _systemGestureInsetsTestValue ?? _window.systemGestureInsets; - WindowPadding? _systemGestureInsetsTestValue; + ui.WindowPadding get systemGestureInsets => _systemGestureInsetsTestValue ?? _window.systemGestureInsets; + ui.WindowPadding? _systemGestureInsetsTestValue; /// Hides the real system gesture insets and reports the given [systemGestureInsetsTestValue] instead. - set systemGestureInsetsTestValue(WindowPadding systemGestureInsetsTestValue) { + set systemGestureInsetsTestValue(ui.WindowPadding systemGestureInsetsTestValue) { _systemGestureInsetsTestValue = systemGestureInsetsTestValue; onMetricsChanged?.call(); } @@ -145,17 +147,18 @@ class TestWindow implements Window { } @override - VoidCallback? get onMetricsChanged => _window.onMetricsChanged; + ui.VoidCallback? get onMetricsChanged => platformDispatcher.onMetricsChanged; @override - set onMetricsChanged(VoidCallback? callback) { - _window.onMetricsChanged = callback; + set onMetricsChanged(ui.VoidCallback? callback) { + platformDispatcher.onMetricsChanged = callback; } @override - Locale? get locale => _localeTestValue ?? _window.locale; - Locale? _localeTestValue; + // ignore: unnecessary_non_null_assertion + ui.Locale get locale => _localeTestValue ?? platformDispatcher.locale!; + ui.Locale? _localeTestValue; /// Hides the real locale and reports the given [localeTestValue] instead. - set localeTestValue(Locale localeTestValue) { + set localeTestValue(ui.Locale localeTestValue) { _localeTestValue = localeTestValue; onLocaleChanged?.call(); } @@ -166,10 +169,11 @@ class TestWindow implements Window { } @override - List? get locales => _localesTestValue ?? _window.locales; - List? _localesTestValue; + // ignore: unnecessary_non_null_assertion + List get locales => _localesTestValue ?? platformDispatcher.locales!; + List? _localesTestValue; /// Hides the real locales and reports the given [localesTestValue] instead. - set localesTestValue(List localesTestValue) { + set localesTestValue(List localesTestValue) { _localesTestValue = localesTestValue; onLocaleChanged?.call(); } @@ -180,10 +184,10 @@ class TestWindow implements Window { } @override - VoidCallback? get onLocaleChanged => _window.onLocaleChanged; + ui.VoidCallback? get onLocaleChanged => platformDispatcher.onLocaleChanged; @override - set onLocaleChanged(VoidCallback? callback) { - _window.onLocaleChanged = callback; + set onLocaleChanged(ui.VoidCallback? callback) { + platformDispatcher.onLocaleChanged = callback; } @override @@ -195,7 +199,7 @@ class TestWindow implements Window { } @override - double get textScaleFactor => _textScaleFactorTestValue ?? _window.textScaleFactor; + double get textScaleFactor => _textScaleFactorTestValue ?? platformDispatcher.textScaleFactor; double? _textScaleFactorTestValue; /// Hides the real text scale factor and reports the given /// [textScaleFactorTestValue] instead. @@ -211,17 +215,17 @@ class TestWindow implements Window { } @override - Brightness get platformBrightness => _platformBrightnessTestValue ?? _window.platformBrightness; - Brightness? _platformBrightnessTestValue; + ui.Brightness get platformBrightness => _platformBrightnessTestValue ?? platformDispatcher.platformBrightness; + ui.Brightness? _platformBrightnessTestValue; @override - VoidCallback? get onPlatformBrightnessChanged => _window.onPlatformBrightnessChanged; + ui.VoidCallback? get onPlatformBrightnessChanged => platformDispatcher.onPlatformBrightnessChanged; @override - set onPlatformBrightnessChanged(VoidCallback? callback) { - _window.onPlatformBrightnessChanged = callback; + set onPlatformBrightnessChanged(ui.VoidCallback? callback) { + platformDispatcher.onPlatformBrightnessChanged = callback; } /// Hides the real text scale factor and reports the given /// [platformBrightnessTestValue] instead. - set platformBrightnessTestValue(Brightness platformBrightnessTestValue) { + set platformBrightnessTestValue(ui.Brightness platformBrightnessTestValue) { _platformBrightnessTestValue = platformBrightnessTestValue; onPlatformBrightnessChanged?.call(); } @@ -233,7 +237,7 @@ class TestWindow implements Window { } @override - bool get alwaysUse24HourFormat => _alwaysUse24HourFormatTestValue ?? _window.alwaysUse24HourFormat; + bool get alwaysUse24HourFormat => _alwaysUse24HourFormatTestValue ?? platformDispatcher.alwaysUse24HourFormat; bool? _alwaysUse24HourFormatTestValue; /// Hides the real clock format and reports the given /// [alwaysUse24HourFormatTestValue] instead. @@ -247,42 +251,42 @@ class TestWindow implements Window { } @override - VoidCallback? get onTextScaleFactorChanged => _window.onTextScaleFactorChanged; + ui.VoidCallback? get onTextScaleFactorChanged => platformDispatcher.onTextScaleFactorChanged; @override - set onTextScaleFactorChanged(VoidCallback? callback) { - _window.onTextScaleFactorChanged = callback; + set onTextScaleFactorChanged(ui.VoidCallback? callback) { + platformDispatcher.onTextScaleFactorChanged = callback; } @override - FrameCallback? get onBeginFrame => _window.onBeginFrame; + ui.FrameCallback? get onBeginFrame => platformDispatcher.onBeginFrame; @override - set onBeginFrame(FrameCallback? callback) { - _window.onBeginFrame = callback; + set onBeginFrame(ui.FrameCallback? callback) { + platformDispatcher.onBeginFrame = callback; } @override - VoidCallback? get onDrawFrame => _window.onDrawFrame; + ui.VoidCallback? get onDrawFrame => platformDispatcher.onDrawFrame; @override - set onDrawFrame(VoidCallback? callback) { - _window.onDrawFrame = callback; + set onDrawFrame(ui.VoidCallback? callback) { + platformDispatcher.onDrawFrame = callback; } @override - TimingsCallback? get onReportTimings => _window.onReportTimings; + ui.TimingsCallback? get onReportTimings => platformDispatcher.onReportTimings; @override - set onReportTimings(TimingsCallback? callback) { - _window.onReportTimings = callback; + set onReportTimings(ui.TimingsCallback? callback) { + platformDispatcher.onReportTimings = callback; } @override - PointerDataPacketCallback? get onPointerDataPacket => _window.onPointerDataPacket; + ui.PointerDataPacketCallback? get onPointerDataPacket => platformDispatcher.onPointerDataPacket; @override - set onPointerDataPacket(PointerDataPacketCallback? callback) { - _window.onPointerDataPacket = callback; + set onPointerDataPacket(ui.PointerDataPacketCallback? callback) { + platformDispatcher.onPointerDataPacket = callback; } @override - String get defaultRouteName => _defaultRouteNameTestValue ?? _window.defaultRouteName; + String get defaultRouteName => _defaultRouteNameTestValue ?? platformDispatcher.defaultRouteName; String? _defaultRouteNameTestValue; /// Hides the real default route name and reports the given /// [defaultRouteNameTestValue] instead. @@ -297,16 +301,16 @@ class TestWindow implements Window { @override void scheduleFrame() { - _window.scheduleFrame(); + platformDispatcher.scheduleFrame(); } @override - void render(Scene scene) { + void render(ui.Scene scene) { _window.render(scene); } @override - bool get semanticsEnabled => _semanticsEnabledTestValue ?? _window.semanticsEnabled; + bool get semanticsEnabled => _semanticsEnabledTestValue ?? platformDispatcher.semanticsEnabled; bool? _semanticsEnabledTestValue; /// Hides the real semantics enabled and reports the given /// [semanticsEnabledTestValue] instead. @@ -322,25 +326,25 @@ class TestWindow implements Window { } @override - VoidCallback? get onSemanticsEnabledChanged => _window.onSemanticsEnabledChanged; + ui.VoidCallback? get onSemanticsEnabledChanged => platformDispatcher.onSemanticsEnabledChanged; @override - set onSemanticsEnabledChanged(VoidCallback? callback) { - _window.onSemanticsEnabledChanged = callback; + set onSemanticsEnabledChanged(ui.VoidCallback? callback) { + platformDispatcher.onSemanticsEnabledChanged = callback; } @override - SemanticsActionCallback? get onSemanticsAction => _window.onSemanticsAction; + ui.SemanticsActionCallback? get onSemanticsAction => platformDispatcher.onSemanticsAction; @override - set onSemanticsAction(SemanticsActionCallback? callback) { - _window.onSemanticsAction = callback; + set onSemanticsAction(ui.SemanticsActionCallback? callback) { + platformDispatcher.onSemanticsAction = callback; } @override - AccessibilityFeatures get accessibilityFeatures => _accessibilityFeaturesTestValue ?? _window.accessibilityFeatures; - AccessibilityFeatures? _accessibilityFeaturesTestValue; + ui.AccessibilityFeatures get accessibilityFeatures => _accessibilityFeaturesTestValue ?? platformDispatcher.accessibilityFeatures; + ui.AccessibilityFeatures? _accessibilityFeaturesTestValue; /// Hides the real accessibility features and reports the given /// [accessibilityFeaturesTestValue] instead. - set accessibilityFeaturesTestValue(AccessibilityFeatures accessibilityFeaturesTestValue) { + set accessibilityFeaturesTestValue(ui.AccessibilityFeatures accessibilityFeaturesTestValue) { _accessibilityFeaturesTestValue = accessibilityFeaturesTestValue; onAccessibilityFeaturesChanged?.call(); } @@ -352,41 +356,44 @@ class TestWindow implements Window { } @override - VoidCallback? get onAccessibilityFeaturesChanged => _window.onAccessibilityFeaturesChanged; + ui.VoidCallback? get onAccessibilityFeaturesChanged => platformDispatcher.onAccessibilityFeaturesChanged; @override - set onAccessibilityFeaturesChanged(VoidCallback? callback) { - _window.onAccessibilityFeaturesChanged = callback; + set onAccessibilityFeaturesChanged(ui.VoidCallback? callback) { + platformDispatcher.onAccessibilityFeaturesChanged = callback; } @override - void updateSemantics(SemanticsUpdate update) { - _window.updateSemantics(update); + void updateSemantics(ui.SemanticsUpdate update) { + platformDispatcher.updateSemantics(update); } @override void setIsolateDebugName(String name) { - _window.setIsolateDebugName(name); + platformDispatcher.setIsolateDebugName(name); } @override void sendPlatformMessage( String name, ByteData? data, - PlatformMessageResponseCallback? callback, + ui.PlatformMessageResponseCallback? callback, ) { - _window.sendPlatformMessage(name, data, callback); + platformDispatcher.sendPlatformMessage(name, data, callback); } @override - PlatformMessageCallback? get onPlatformMessage => _window.onPlatformMessage; + ui.PlatformMessageCallback? get onPlatformMessage => platformDispatcher.onPlatformMessage; @override - set onPlatformMessage(PlatformMessageCallback? callback) { - _window.onPlatformMessage = callback; + set onPlatformMessage(ui.PlatformMessageCallback? callback) { + platformDispatcher.onPlatformMessage = callback; } + @override + ui.PlatformDispatcher get platformDispatcher => _window.platformDispatcher; + /// Delete any test value properties that have been set on this [TestWindow] - /// and return to reporting the real [Window] values for all [Window] - /// properties. + /// and return to reporting the real [SingletonFlutterWindow] values for all + /// [SingletonFlutterWindow] properties. /// /// If desired, clearing of properties can be done on an individual basis, /// e.g., [clearLocaleTestValue()]. diff --git a/packages/flutter_tools/lib/src/plugins.dart b/packages/flutter_tools/lib/src/plugins.dart index 3d5292b98a..543b0fa801 100644 --- a/packages/flutter_tools/lib/src/plugins.dart +++ b/packages/flutter_tools/lib/src/plugins.dart @@ -1100,7 +1100,7 @@ void handleSymlinkException(FileSystemException e, { if (platform.isWindows && (e.osError?.errorCode ?? 0) == 1314) { final String versionString = RegExp(r'[\d.]+').firstMatch(os.name)?.group(0); final Version version = Version.parse(versionString); - // Window 10 14972 is the oldest version that allows creating symlinks + // Windows 10 14972 is the oldest version that allows creating symlinks // just by enabling developer mode; before that it requires running the // terminal as Administrator. // https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/