Implement PlatformDispatcher.displays on web (flutter/engine#42297)

I missed this before.
This commit is contained in:
Dan Field 2023-05-25 09:46:58 -07:00 committed by GitHub
parent 57fb0c0135
commit 45c1fe4348
3 changed files with 31 additions and 25 deletions

View File

@ -73,6 +73,24 @@ class HighContrastSupport {
}
}
class EngineFlutterDisplay extends ui.Display {
EngineFlutterDisplay({
required this.id,
required this.devicePixelRatio,
required this.size,
required this.refreshRate,
});
@override
final int id;
@override
final double devicePixelRatio;
@override
final ui.Size size;
@override
final double refreshRate;
}
/// Platform event dispatcher.
///
/// This is the central entry point for platform messages and configuration
@ -135,7 +153,14 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
}
@override
Iterable<ui.Display> get displays => <ui.Display>[];
Iterable<ui.Display> get displays => <ui.Display>[
EngineFlutterDisplay(
id: 0,
size: ui.Size(domWindow.screen?.width ?? 0, domWindow.screen?.height ?? 0),
devicePixelRatio: domWindow.devicePixelRatio,
refreshRate: 60,
)
];
/// The current list of windows.
@override

View File

@ -29,24 +29,6 @@ const bool debugPrintPlatformMessages = false;
/// The view ID for the implicit flutter view provided by the platform.
const int kImplicitViewId = 0;
class EngineFlutterDisplay extends ui.Display {
EngineFlutterDisplay({
required this.id,
required this.devicePixelRatio,
required this.size,
required this.refreshRate,
});
@override
final int id;
@override
final double devicePixelRatio;
@override
final ui.Size size;
@override
final double refreshRate;
}
/// The Web implementation of [ui.SingletonFlutterWindow].
class EngineFlutterWindow extends ui.SingletonFlutterWindow {
EngineFlutterWindow(this.viewId, this.platformDispatcher) {
@ -66,12 +48,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
@override
ui.Display get display {
return EngineFlutterDisplay(
id: 0,
size: ui.Size(domWindow.screen?.width ?? 0, domWindow.screen?.height ?? 0),
devicePixelRatio: domWindow.devicePixelRatio,
refreshRate: 60,
);
return ui.PlatformDispatcher.instance.displays.first;
}
@override

View File

@ -18,6 +18,10 @@ void testMain() {
ensureFlutterViewEmbedderInitialized();
group('PlatformDispatcher', () {
test('reports at least one display', () {
expect(ui.PlatformDispatcher.instance.displays.length, greaterThan(0));
});
test('high contrast in accessibilityFeatures has the correct value', () {
final MockHighContrastSupport mockHighContrast =
MockHighContrastSupport();