TestWindow class

Deprecated. Will be removed in a future version of Flutter.

This class has been deprecated to prepare for Flutter's upcoming support for multiple views and multiple windows.

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 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

A test can utilize a TestWindow in the following way:

testWidgets('your test name here', (WidgetTester tester) async {
  // Retrieve the TestWidgetsFlutterBinding.
  final TestWidgetsFlutterBinding testBinding = tester.binding;

  // Fake the desired properties of the TestWindow. All code running
  // within this test will perceive the following fake text scale
  // factor as the real text scale factor of the window.
  testBinding.platformDispatcher.textScaleFactorTestValue = 2.5;

  // Test code that depends on text scale factor here.
});

The TestWidgetsFlutterBinding is recreated for each test and therefore any fake values defined in one test will not persist to the next.

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., clearDevicePixelRatioTestValue.

To clear all fake test values in a TestWindow, consider using clearAllTestValues.

See also:

Implemented types
Available Extensions
Annotations
  • @Deprecated('Use TestPlatformDispatcher (via WidgetTester.platformDispatcher) or TestFlutterView (via WidgetTester.view) instead. ' 'Deprecated to prepare for the upcoming multi-window support. ' 'This feature was deprecated after v3.9.0-0.1.pre.')

Constructors

TestWindow({required SingletonFlutterWindow window})
Constructs a TestWindow that defers all behavior to the given SingletonFlutterWindow unless explicitly overridden for test purposes.
TestWindow.fromPlatformDispatcher({@Deprecated('Use WidgetTester.platformDispatcher instead. ' 'Deprecated to prepare for the upcoming multi-window support. ' 'This feature was deprecated after v3.9.0-0.1.pre.') required TestPlatformDispatcher platformDispatcher})
Constructs a TestWindow that defers all behavior to the given TestPlatformDispatcher and its TestPlatformDispatcher.implicitView.

Properties

accessibilityFeatures AccessibilityFeatures
Additional accessibility features that may be enabled by the platform.
read-onlyoverride
alwaysUse24HourFormat bool
The setting indicating whether time should always be shown in the 24-hour format.
read-onlyoverride
brieflyShowPassword bool
Whether briefly displaying the characters as you type in obscured text fields is enabled in system settings.
read-onlyoverride
defaultRouteName String
The route or path that the embedder requested when the application was launched.
read-onlyoverride
devicePixelRatio double
The number of device pixels for each logical pixel for the screen this view is displayed on.
read-onlyoverride
devicePixelRatioTestValue double
Hides the real device pixel ratio and reports the given devicePixelRatio instead.
write-only
display Display
The Display this view is drawn in.
read-onlyinherited
displayFeatures List<DisplayFeature>
Areas of the display that are obstructed by hardware features.
read-onlyoverride
displayFeaturesTestValue List<DisplayFeature>
Hides the real displayFeatures and reports the given displayFeaturesTestValue instead.
write-only
frameData FrameData
The FrameData object for the current frame.
read-onlyoverride
gestureSettings GestureSettings
Additional configuration for touch gestures performed on this view.
read-onlyoverride
gestureSettingsTestValue GestureSettings
Hides the real gesture settings and reports the given gestureSettingsTestValue instead.
write-only
hashCode int
The hash code for this object.
read-onlyinherited
initialLifecycleState String
The lifecycle state immediately after dart isolate initialization.
read-onlyoverride
locale Locale
The system-reported default locale of the device.
read-onlyoverride
locales List<Locale>
The full system-reported supported locales of the device.
read-onlyoverride
nativeSpellCheckServiceDefined bool
Whether the spell check service is supported on the current platform.
read-onlyoverride
nativeSpellCheckServiceDefinedTestValue bool
write-only
onAccessibilityFeaturesChanged VoidCallback?
A callback that is invoked when the value of accessibilityFeatures changes.
read / writeoverride
onBeginFrame FrameCallback?
A callback that is invoked to notify the window that it is an appropriate time to provide a scene using the SceneBuilder API and the render method.
read / writeoverride
onDrawFrame VoidCallback?
A callback that is invoked for each frame after onBeginFrame has completed and after the microtask queue has been drained.
read / writeoverride
onFrameDataChanged VoidCallback?
A callback that is invoked when the window updates the FrameData.
read / writeoverride
onKeyData KeyDataCallback?
A callback that is invoked when key data is available.
read / writeoverride
onLocaleChanged VoidCallback?
A callback that is invoked whenever locale changes value.
read / writeoverride
onMetricsChanged VoidCallback?
A callback that is invoked whenever the devicePixelRatio, physicalSize, padding, viewInsets, PlatformDispatcher.views, or systemGestureInsets values change.
read / writeoverride
onPlatformBrightnessChanged VoidCallback?
A callback that is invoked whenever platformBrightness changes value.
read / writeoverride
onPlatformMessage PlatformMessageCallback?
Deprecated. Migrate to ChannelBuffers.setListener instead.
read / writeinherited
onPointerDataPacket PointerDataPacketCallback?
A callback that is invoked when pointer data is available.
read / writeoverride
onReportTimings TimingsCallback?
A callback that is invoked to report the FrameTiming of recently rasterized frames.
read / writeoverride
onSemanticsEnabledChanged VoidCallback?
A callback that is invoked when the value of semanticsEnabled changes.
read / writeoverride
onSystemFontFamilyChanged VoidCallback?
A callback that is invoked whenever systemFontFamily changes value.
read / writeoverride
onTextScaleFactorChanged VoidCallback?
A callback that is invoked whenever textScaleFactor changes value.
read / writeoverride
padding ViewPadding
The number of physical pixels on each side of the display rectangle into which the view can render, but which may be partially obscured by system UI (such as the system notification area), or physical intrusions in the display (e.g. overscan regions on television screens or phone sensor housings).
read-onlyoverride
paddingTestValue ViewPadding
Hides the real padding and reports the given paddingTestValue instead.
write-only
physicalGeometry Rect
The dimensions and location of the rectangle into which the scene rendered in this view will be drawn on the screen, in physical pixels.
read-onlyoverride
physicalSize Size
The dimensions of the rectangle into which the scene rendered in this view will be drawn on the screen, in physical pixels.
read-onlyoverride
physicalSizeTestValue Size
Hides the real physical size and reports the given physicalSizeTestValue instead.
write-only
platformBrightness Brightness
The setting indicating the current brightness mode of the host platform.
read-onlyoverride
platformDispatcher TestPlatformDispatcher
The platform dispatcher that this view is registered with, and gets its information from.
final
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited
semanticsEnabled bool
Whether the user has requested that updateSemantics be called when the semantic contents of window changes.
read-onlyoverride
systemFontFamily String?
The setting indicating the system font of the host platform.
read-onlyoverride
systemGestureInsets ViewPadding
The number of physical pixels on each side of the display rectangle into which the view can render, but where the operating system will consume input gestures for the sake of system navigation.
read-onlyoverride
systemGestureInsetsTestValue ViewPadding
Hides the real system gesture insets and reports the given systemGestureInsetsTestValue instead.
write-only
textScaleFactor double
The system-reported text scale.
read-onlyoverride
viewId int
The opaque ID for this view.
read-onlyoverride
viewInsets ViewPadding
The number of physical pixels on each side of the display rectangle into which the view can render, but over which the operating system will likely place system UI, such as the keyboard, that fully obscures any content.
read-onlyoverride
viewInsetsTestValue ViewPadding
Hides the real view insets and reports the given viewInsetsTestValue instead.
write-only
viewPadding ViewPadding
The number of physical pixels on each side of the display rectangle into which the view can render, but which may be partially obscured by system UI (such as the system notification area), or physical intrusions in the display (e.g. overscan regions on television screens or phone sensor housings).
read-onlyoverride
viewPaddingTestValue ViewPadding
Hides the real view padding and reports the given paddingTestValue instead.
write-only

Methods

clearAllTestValues() → void
Delete any test value properties that have been set on this TestWindow as well as its platformDispatcher.
clearDevicePixelRatioTestValue() → void
Deletes any existing test device pixel ratio and returns to using the real device pixel ratio.
clearDisplayFeaturesTestValue() → void
Deletes any existing test padding and returns to using the real padding.
clearGestureSettingsTestValue() → void
Deletes any existing test gesture settings and returns to using the real gesture settings.
clearPaddingTestValue() → void
Deletes any existing test padding and returns to using the real padding.
clearPhysicalSizeTestValue() → void
Deletes any existing test physical size and returns to using the real physical size.
clearSystemGestureInsetsTestValue() → void
Deletes any existing test system gesture insets and returns to using the real system gesture insets.
clearViewInsetsTestValue() → void
Deletes any existing test view insets and returns to using the real view insets.
clearViewPaddingTestValue() → void
Deletes any existing test view padding and returns to using the real viewPadding.
computePlatformResolvedLocale(List<Locale> supportedLocales) Locale?
Performs the platform-native locale resolution.
override
noSuchMethod(Invocation invocation) → dynamic
This gives us some grace time when the dart:ui side adds something to SingletonFlutterWindow, and makes things easier when we do rolls to give us time to catch up.
override
render(Scene scene) → void
Updates the view's rendering on the GPU with the newly provided Scene.
override
scheduleFrame() → void
Requests that, at the next appropriate opportunity, the onBeginFrame and onDrawFrame callbacks be invoked.
override
sendPlatformMessage(String name, ByteData? data, PlatformMessageResponseCallback? callback) → void
Sends a message to a platform-specific plugin.
override
setIsolateDebugName(String name) → void
Set the debug name associated with this platform dispatcher's root isolate.
override
toString() String
A string representation of this object.
inherited
updateSemantics(SemanticsUpdate update) → void
Change the retained semantics data about this FlutterView.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited