Remvoe last few references to window singleton (#122644)
Remove last few references to window singleton
This commit is contained in:
parent
0ba64488da
commit
a599c08c32
@ -288,7 +288,7 @@ mixin GestureBinding on BindingBase implements HitTestable, HitTestDispatcher, H
|
||||
// We convert pointer data to logical pixels so that e.g. the touch slop can be
|
||||
// defined in a device-independent manner.
|
||||
try {
|
||||
_pendingPointerEvents.addAll(PointerEventConverter.expand(packet.data, window.devicePixelRatio));
|
||||
_pendingPointerEvents.addAll(PointerEventConverter.expand(packet.data, platformDispatcher.implicitView!.devicePixelRatio));
|
||||
if (!locked) {
|
||||
_flushPointerEventQueue();
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
|
||||
_debugIsRenderViewInitialized = true;
|
||||
return true;
|
||||
}());
|
||||
renderView = RenderView(configuration: createViewConfiguration(), window: window);
|
||||
renderView = RenderView(configuration: createViewConfiguration(), window: platformDispatcher.implicitView!);
|
||||
renderView.prepareInitialFrame();
|
||||
}
|
||||
bool _debugIsRenderViewInitialized = false;
|
||||
@ -300,9 +300,10 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture
|
||||
/// this to force the display into 800x600 when a test is run on the device
|
||||
/// using `flutter run`.
|
||||
ViewConfiguration createViewConfiguration() {
|
||||
final double devicePixelRatio = window.devicePixelRatio;
|
||||
final FlutterView view = platformDispatcher.implicitView!;
|
||||
final double devicePixelRatio = view.devicePixelRatio;
|
||||
return ViewConfiguration(
|
||||
size: window.physicalSize / devicePixelRatio,
|
||||
size: view.physicalSize / devicePixelRatio,
|
||||
devicePixelRatio: devicePixelRatio,
|
||||
);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ void main() {
|
||||
expect(events.length, 1);
|
||||
expect(events[0], isA<PointerDownEvent>());
|
||||
expect(events[0].timeStamp, binding.frameTime! + samplingOffset);
|
||||
expect(events[0].position, Offset(0.0 / GestureBinding.instance.window.devicePixelRatio, 0.0));
|
||||
expect(events[0].position, Offset(0.0 / _devicePixelRatio, 0.0));
|
||||
|
||||
// Second frame callback should have been requested.
|
||||
callback = binding.postFrameCallback;
|
||||
@ -155,8 +155,8 @@ void main() {
|
||||
expect(events.length, 2);
|
||||
expect(events[1], isA<PointerMoveEvent>());
|
||||
expect(events[1].timeStamp, binding.frameTime! + samplingOffset);
|
||||
expect(events[1].position, Offset(10.0 / GestureBinding.instance.window.devicePixelRatio, 0.0));
|
||||
expect(events[1].delta, Offset(10.0 / GestureBinding.instance.window.devicePixelRatio, 0.0));
|
||||
expect(events[1].position, Offset(10.0 / _devicePixelRatio, 0.0));
|
||||
expect(events[1].delta, Offset(10.0 / _devicePixelRatio, 0.0));
|
||||
|
||||
// Verify that resampling continues without a frame callback.
|
||||
async.elapse(frameInterval * 1.5);
|
||||
@ -183,3 +183,5 @@ void main() {
|
||||
GestureBinding.instance.resamplingEnabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
double get _devicePixelRatio => GestureBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
|
||||
|
@ -18,7 +18,6 @@ void main() {
|
||||
final List<TestMenu> opened = <TestMenu>[];
|
||||
final List<TestMenu> closed = <TestMenu>[];
|
||||
final GlobalKey menuItemKey = GlobalKey();
|
||||
late Size defaultSize;
|
||||
|
||||
void onPressed(TestMenu item) {
|
||||
selected.add(item);
|
||||
@ -36,11 +35,6 @@ void main() {
|
||||
focusedMenu = (primaryFocus?.debugLabel ?? primaryFocus).toString();
|
||||
}
|
||||
|
||||
setUpAll(() {
|
||||
final MediaQueryData mediaQueryData = MediaQueryData.fromView(TestWidgetsFlutterBinding.instance.window);
|
||||
defaultSize = mediaQueryData.size;
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
focusedMenu = null;
|
||||
selected.clear();
|
||||
@ -53,7 +47,7 @@ void main() {
|
||||
Future<void> changeSurfaceSize(WidgetTester tester, Size size) async {
|
||||
await tester.binding.setSurfaceSize(size);
|
||||
addTearDown(() async {
|
||||
await tester.binding.setSurfaceSize(defaultSize);
|
||||
await tester.binding.setSurfaceSize(null);
|
||||
});
|
||||
}
|
||||
|
||||
@ -1395,7 +1389,7 @@ void main() {
|
||||
|
||||
testWidgets('menus close on view size change', (WidgetTester tester) async {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
final MediaQueryData mediaQueryData = MediaQueryData.fromView(tester.binding.window);
|
||||
final MediaQueryData mediaQueryData = MediaQueryData.fromView(tester.view);
|
||||
|
||||
Widget build(Size size) {
|
||||
return MaterialApp(
|
||||
|
@ -438,10 +438,11 @@ ui.PointerData _pointerData(
|
||||
int device = 0,
|
||||
PointerDeviceKind kind = PointerDeviceKind.mouse,
|
||||
}) {
|
||||
final double devicePixelRatio = RendererBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
|
||||
return ui.PointerData(
|
||||
change: change,
|
||||
physicalX: logicalPosition.dx * RendererBinding.instance.window.devicePixelRatio,
|
||||
physicalY: logicalPosition.dy * RendererBinding.instance.window.devicePixelRatio,
|
||||
physicalX: logicalPosition.dx * devicePixelRatio,
|
||||
physicalY: logicalPosition.dy * devicePixelRatio,
|
||||
kind: kind,
|
||||
device: device,
|
||||
);
|
||||
|
@ -592,10 +592,11 @@ ui.PointerData _pointerData(
|
||||
int device = 0,
|
||||
PointerDeviceKind kind = PointerDeviceKind.mouse,
|
||||
}) {
|
||||
final double devicePixelRatio = RendererBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
|
||||
return ui.PointerData(
|
||||
change: change,
|
||||
physicalX: logicalPosition.dx * RendererBinding.instance.window.devicePixelRatio,
|
||||
physicalY: logicalPosition.dy * RendererBinding.instance.window.devicePixelRatio,
|
||||
physicalX: logicalPosition.dx * devicePixelRatio,
|
||||
physicalY: logicalPosition.dy * devicePixelRatio,
|
||||
kind: kind,
|
||||
device: device,
|
||||
);
|
||||
|
@ -305,12 +305,13 @@ ui.PointerData _pointerData(
|
||||
PointerDeviceKind kind = PointerDeviceKind.mouse,
|
||||
int pointer = 0,
|
||||
}) {
|
||||
final double devicePixelRatio = RendererBinding.instance.platformDispatcher.implicitView!.devicePixelRatio;
|
||||
return ui.PointerData(
|
||||
pointerIdentifier: pointer,
|
||||
embedderId: pointer,
|
||||
change: change,
|
||||
physicalX: logicalPosition.dx * RendererBinding.instance.window.devicePixelRatio,
|
||||
physicalY: logicalPosition.dy * RendererBinding.instance.window.devicePixelRatio,
|
||||
physicalX: logicalPosition.dx * devicePixelRatio,
|
||||
physicalY: logicalPosition.dy * devicePixelRatio,
|
||||
kind: kind,
|
||||
device: device,
|
||||
);
|
||||
|
@ -1098,7 +1098,7 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('MediaQueryData.fromWindow is created using window values', (WidgetTester tester) async {
|
||||
final MediaQueryData windowData = MediaQueryData.fromWindow(tester.binding.window);
|
||||
final MediaQueryData windowData = MediaQueryData.fromWindow(tester.view);
|
||||
late MediaQueryData fromWindowData;
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -206,7 +206,7 @@ void main() {
|
||||
const MaterialPage<void> page = MaterialPage<void>(child: Text('page'));
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.binding.window),
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Navigator(
|
||||
@ -221,7 +221,7 @@ void main() {
|
||||
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.binding.window),
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Navigator(
|
||||
@ -2810,7 +2810,7 @@ void main() {
|
||||
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.binding.window),
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: Localizations(
|
||||
locale: const Locale('en', 'US'),
|
||||
delegates: const <LocalizationsDelegate<dynamic>>[
|
||||
@ -2849,7 +2849,7 @@ void main() {
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.binding.window),
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: Localizations(
|
||||
locale: const Locale('en', 'US'),
|
||||
delegates: const <LocalizationsDelegate<dynamic>>[
|
||||
|
@ -96,7 +96,7 @@ void main() {
|
||||
Widget deepChild = Container();
|
||||
|
||||
await tester.pumpWidget(MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.binding.window),
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
|
@ -34,7 +34,7 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async {
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.binding.window),
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: Navigator(
|
||||
key: navigatorKey,
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
|
@ -301,7 +301,7 @@ void main() {
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: MediaQuery(
|
||||
data: MediaQueryData.fromView(tester.binding.window),
|
||||
data: MediaQueryData.fromView(tester.view),
|
||||
child: Material(
|
||||
child: Center(
|
||||
child: Slider(
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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!,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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: () {},
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -118,11 +118,12 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
|
||||
|
||||
@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 TestViewConfiguration.fromView(
|
||||
size: size,
|
||||
view: window,
|
||||
view: view,
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user