Remvoe last few references to window singleton (#122644)

Remove last few references to window singleton
This commit is contained in:
Michael Goderbauer
2023-03-14 17:34:34 -07:00
committed by GitHub
parent 0ba64488da
commit a599c08c32
18 changed files with 51 additions and 46 deletions

View File

@@ -58,12 +58,13 @@ class MatchesGoldenFile extends AsyncMatcher {
final Size size = renderObject.paintBounds.size;
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.instance;
final Element e = binding.renderViewElement!;
final ui.FlutterView view = binding.platformDispatcher.implicitView!;
// Unlike `flutter_tester`, we don't have the ability to render an element
// to an image directly. Instead, we will use `window.render()` to render
// only the element being requested, and send a request to the test server
// requesting it to take a screenshot through the browser's debug interface.
_renderElement(binding.window, renderObject);
_renderElement(view, renderObject);
final String? result = await binding.runAsync<String?>(() async {
if (autoUpdateGoldenFiles) {
await webGoldenComparator.update(size.width, size.height, key);
@@ -76,7 +77,7 @@ class MatchesGoldenFile extends AsyncMatcher {
return ex.message;
}
}, additionalTime: const Duration(seconds: 22));
_renderElement(binding.window, _findRepaintBoundary(e));
_renderElement(view, _findRepaintBoundary(e));
return result;
}

View File

@@ -485,8 +485,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
@override
ViewConfiguration createViewConfiguration() {
final double devicePixelRatio = window.devicePixelRatio;
final Size size = _surfaceSize ?? window.physicalSize / devicePixelRatio;
final FlutterView view = platformDispatcher.implicitView!;
final double devicePixelRatio = view.devicePixelRatio;
final Size size = _surfaceSize ?? view.physicalSize / devicePixelRatio;
return ViewConfiguration(
size: size,
devicePixelRatio: devicePixelRatio,
@@ -1730,7 +1731,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
renderView = _LiveTestRenderView(
configuration: createViewConfiguration(),
onNeedPaint: _handleViewNeedsPaint,
window: window,
window: platformDispatcher.implicitView!,
);
renderView.prepareInitialFrame();
}
@@ -1921,7 +1922,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
ViewConfiguration createViewConfiguration() {
return TestViewConfiguration.fromView(
size: _surfaceSize ?? _kDefaultTestViewportSize,
view: window,
view: platformDispatcher.implicitView!,
);
}

View File

@@ -7,8 +7,9 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Fails correctly with configured screen size - small', (WidgetTester tester) async {
tester.binding.window.devicePixelRatioTestValue = 1.2;
tester.binding.window.physicalSizeTestValue = const Size(250, 300);
tester.view.devicePixelRatio = 1.2;
tester.view.physicalSize = const Size(250, 300);
addTearDown(tester.view.reset);
final Widget invalidButton = ElevatedButton(
onPressed: () {},
@@ -25,8 +26,9 @@ void main() {
});
testWidgets('Fails correctly with configured screen size - large', (WidgetTester tester) async {
tester.binding.window.devicePixelRatioTestValue = 4.2;
tester.binding.window.physicalSizeTestValue = const Size(2500, 3000);
tester.view.devicePixelRatio = 4.2;
tester.view.physicalSize = const Size(2500, 3000);
addTearDown(tester.view.reset);
final Widget invalidButton = ElevatedButton(
onPressed: () {},

View File

@@ -71,8 +71,8 @@ void main() {
testWidgets('setSurfaceSize works', (WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(home: Center(child: Text('Test'))));
final Size windowCenter = tester.binding.window.physicalSize /
tester.binding.window.devicePixelRatio /
final Size windowCenter = tester.view.physicalSize /
tester.view.devicePixelRatio /
2;
final double windowCenterX = windowCenter.width;
final double windowCenterY = windowCenter.height;

View File

@@ -34,8 +34,8 @@ void main() {
),
);
final Size windowCenter = tester.binding.window.physicalSize /
tester.binding.window.devicePixelRatio /
final Size windowCenter = tester.view.physicalSize /
tester.view.devicePixelRatio /
2;
final double windowCenterX = windowCenter.width;
final double windowCenterY = windowCenter.height;