From d24c01bd0c41331bd17165e0173b24c5d05d7c0a Mon Sep 17 00:00:00 2001 From: Lau Ching Jun Date: Thu, 14 Dec 2023 11:42:06 -0800 Subject: [PATCH] Revert "Dynamic view sizing" (#140165) Reverts flutter/flutter#138648 This caused the app to be stuck in the splash screen on certain phone models. Context: b/316244317 --- .../flutter/lib/src/rendering/binding.dart | 2 +- packages/flutter/lib/src/rendering/box.dart | 9 +-- packages/flutter/lib/src/rendering/view.dart | 58 +++++------------ .../foundation/service_extensions_test.dart | 3 +- .../test/rendering/box_constraints_test.dart | 15 ----- .../rendering/independent_layout_test.dart | 6 +- .../rendering/multi_view_binding_test.dart | 12 +--- .../flutter/test/rendering/view_test.dart | 37 ++--------- .../independent_widget_layout_test.dart | 4 +- .../flutter/test/widgets/keep_alive_test.dart | 6 +- packages/flutter/test/widgets/view_test.dart | 62 ------------------- .../test/widgets/widget_inspector_test.dart | 9 +-- packages/flutter_test/lib/src/binding.dart | 14 ++--- packages/flutter_test/lib/src/window.dart | 43 +++---------- packages/flutter_test/test/view_test.dart | 54 ---------------- .../test/widget_tester_live_device_test.dart | 2 +- 16 files changed, 44 insertions(+), 292 deletions(-) diff --git a/packages/flutter/lib/src/rendering/binding.dart b/packages/flutter/lib/src/rendering/binding.dart index f9d5c74dd6..82bb2bd933 100644 --- a/packages/flutter/lib/src/rendering/binding.dart +++ b/packages/flutter/lib/src/rendering/binding.dart @@ -350,7 +350,7 @@ mixin RendererBinding on BindingBase, ServicesBinding, SchedulerBinding, Gesture final FlutterView view = renderView.flutterView; final double devicePixelRatio = view.devicePixelRatio; return ViewConfiguration( - constraints: view.physicalConstraints / devicePixelRatio, + size: view.physicalSize / devicePixelRatio, devicePixelRatio: devicePixelRatio, ); } diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index f01a45e621..1449d8b8fb 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'dart:math' as math; -import 'dart:ui' as ui show ViewConstraints, lerpDouble; +import 'dart:ui' as ui show lerpDouble; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; @@ -153,13 +153,6 @@ class BoxConstraints extends Constraints { minHeight = height ?? double.infinity, maxHeight = height ?? double.infinity; - /// Creates box constraints that match the given view constraints. - BoxConstraints.fromViewConstraints(ui.ViewConstraints constraints) - : minWidth = constraints.minWidth, - maxWidth = constraints.maxWidth, - minHeight = constraints.minHeight, - maxHeight = constraints.maxHeight; - /// The minimum width that satisfies the constraints. final double minWidth; diff --git a/packages/flutter/lib/src/rendering/view.dart b/packages/flutter/lib/src/rendering/view.dart index b63164f0ab..03db7f1d60 100644 --- a/packages/flutter/lib/src/rendering/view.dart +++ b/packages/flutter/lib/src/rendering/view.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'dart:io' show Platform; -import 'dart:ui' as ui show FlutterView, Scene, SceneBuilder, SemanticsUpdate, ViewConstraints; +import 'dart:ui' as ui show FlutterView, Scene, SceneBuilder, SemanticsUpdate; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; @@ -19,15 +19,14 @@ import 'object.dart'; class ViewConfiguration { /// Creates a view configuration. /// - /// By default, the view has [ViewConstraints] with all dimensions set to zero - /// (i.e. the view is forced to [Size.zero]) and a [devicePixelRatio] of 1.0. + /// By default, the view has zero [size] and a [devicePixelRatio] of 1.0. const ViewConfiguration({ - this.constraints = const ui.ViewConstraints(maxWidth: 0.0, maxHeight: 0.0), + this.size = Size.zero, this.devicePixelRatio = 1.0, }); - /// The constraints of the output surface in logical pixel. - final ui.ViewConstraints constraints; + /// The size of the output surface. + final Size size; /// The pixel density of the output surface. final double devicePixelRatio; @@ -41,34 +40,21 @@ class ViewConfiguration { return Matrix4.diagonal3Values(devicePixelRatio, devicePixelRatio, 1.0); } - /// Transforms the provided [Size] in logical pixels to physical pixels. - /// - /// The [FlutterView.render] method accepts only sizes in physical pixels, - /// but the framework operates in logical pixels. This method is used to - /// transform the logical size calculated for a [RenderView] back to a - /// physical size suitable to be passed to [FlutterView.render]. - /// - /// By default, this method just multiplies the provided [Size] with the - /// [devicePixelRatio]. - Size toPhysicalSize(Size logicalSize) { - return logicalSize * devicePixelRatio; - } - @override bool operator ==(Object other) { if (other.runtimeType != runtimeType) { return false; } return other is ViewConfiguration - && other.constraints == constraints + && other.size == size && other.devicePixelRatio == devicePixelRatio; } @override - int get hashCode => Object.hash(constraints, devicePixelRatio); + int get hashCode => Object.hash(size, devicePixelRatio); @override - String toString() => '$constraints at ${debugFormatDouble(devicePixelRatio)}x'; + String toString() => '$size at ${debugFormatDouble(devicePixelRatio)}x'; } /// The root of the render tree. @@ -90,10 +76,8 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin RenderBox? child, ViewConfiguration? configuration, required ui.FlutterView view, - }) : _view = view { - if (configuration != null) { - this.configuration = configuration; - } + }) : _configuration = configuration, + _view = view { this.child = child; } @@ -121,7 +105,6 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin } final ViewConfiguration? oldConfiguration = _configuration; _configuration = value; - _constraints = BoxConstraints.fromViewConstraints(configuration.constraints); if (_rootTransform == null) { // [prepareInitialFrame] has not been called yet, nothing to do for now. return; @@ -136,15 +119,6 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin /// Whether a [configuration] has been set. bool get hasConfiguration => _configuration != null; - @override - BoxConstraints get constraints { - if (_constraints == null) { - throw StateError('Constraints are not available because RenderView has not been given a configuration yet.'); - } - return _constraints!; - } - BoxConstraints? _constraints; - /// The [FlutterView] into which this [RenderView] will render. ui.FlutterView get flutterView => _view; final ui.FlutterView _view; @@ -214,13 +188,12 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin @override void performLayout() { assert(_rootTransform != null); - final bool sizedByChild = !constraints.isTight; + _size = configuration.size; + assert(_size.isFinite); + if (child != null) { - child!.layout(constraints, parentUsesSize: sizedByChild); + child!.layout(BoxConstraints.tight(_size)); } - _size = sizedByChild && child != null ? child!.size : constraints.smallest; - assert(size.isFinite); - assert(constraints.isSatisfiedBy(size)); } /// Determines the set of render objects located at the given position. @@ -280,8 +253,7 @@ class RenderView extends RenderObject with RenderObjectWithChildMixin if (automaticSystemUiAdjustment) { _updateSystemChrome(); } - assert(configuration.constraints.isSatisfiedBy(size)); - _view.render(scene, size: configuration.toPhysicalSize(size)); + _view.render(scene); scene.dispose(); assert(() { if (debugRepaintRainbowEnabled || debugRepaintTextRainbowEnabled) { diff --git a/packages/flutter/test/foundation/service_extensions_test.dart b/packages/flutter/test/foundation/service_extensions_test.dart index 81ff3569f7..88056b2589 100644 --- a/packages/flutter/test/foundation/service_extensions_test.dart +++ b/packages/flutter/test/foundation/service_extensions_test.dart @@ -259,8 +259,7 @@ void main() { r' debug mode enabled - [a-zA-Z]+\n' r' view size: Size\(2400\.0, 1800\.0\) \(in physical pixels\)\n' r' device pixel ratio: 3\.0 \(physical pixels per logical pixel\)\n' - r' configuration: ViewConstraints\(w=800\.0, h=600\.0\) at 3\.0x \(in\n' - r' logical pixels\)\n' + r' configuration: Size\(800\.0, 600\.0\) at 3\.0x \(in logical pixels\)\n' r'$', ), }); diff --git a/packages/flutter/test/rendering/box_constraints_test.dart b/packages/flutter/test/rendering/box_constraints_test.dart index 6c6cbe1445..48dadde8d5 100644 --- a/packages/flutter/test/rendering/box_constraints_test.dart +++ b/packages/flutter/test/rendering/box_constraints_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui'; - import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -169,17 +167,4 @@ void main() { expect(copy.minHeight, 11.0); expect(copy.maxHeight, 18.0); }); - - test('BoxConstraints.fromViewConstraints', () { - final BoxConstraints unconstrained = BoxConstraints.fromViewConstraints( - const ViewConstraints(), - ); - expect(unconstrained, const BoxConstraints()); - - final BoxConstraints constraints = BoxConstraints.fromViewConstraints( - const ViewConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4), - ); - expect(constraints, const BoxConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4)); - }); - } diff --git a/packages/flutter/test/rendering/independent_layout_test.dart b/packages/flutter/test/rendering/independent_layout_test.dart index 8f8303ec05..ce40300a52 100644 --- a/packages/flutter/test/rendering/independent_layout_test.dart +++ b/packages/flutter/test/rendering/independent_layout_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show ViewConstraints; - import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -34,8 +32,8 @@ class TestLayout { void main() { TestRenderingFlutterBinding.ensureInitialized(); - final ViewConfiguration testConfiguration = ViewConfiguration( - constraints: ViewConstraints.tight(const Size(800.0, 600.0)), + const ViewConfiguration testConfiguration = ViewConfiguration( + size: Size(800.0, 600.0), ); test('onscreen layout does not affect offscreen', () { diff --git a/packages/flutter/test/rendering/multi_view_binding_test.dart b/packages/flutter/test/rendering/multi_view_binding_test.dart index 5418c34546..4edfbcf312 100644 --- a/packages/flutter/test/rendering/multi_view_binding_test.dart +++ b/packages/flutter/test/rendering/multi_view_binding_test.dart @@ -18,7 +18,7 @@ void main() { binding.addRenderView(view); expect(binding.renderViews, contains(view)); expect(view.configuration.devicePixelRatio, flutterView.devicePixelRatio); - expect(view.configuration.constraints, ViewConstraints.tight(flutterView.physicalSize) / flutterView.devicePixelRatio); + expect(view.configuration.size, flutterView.physicalSize / flutterView.devicePixelRatio); binding.removeRenderView(view); expect(binding.renderViews, isEmpty); @@ -51,17 +51,13 @@ void main() { final RenderView view = RenderView(view: flutterView); binding.addRenderView(view); expect(view.configuration.devicePixelRatio, 2.5); - expect(view.configuration.constraints.isTight, isTrue); - expect(view.configuration.constraints.minWidth, 160.0); - expect(view.configuration.constraints.minHeight, 240.0); + expect(view.configuration.size, const Size(160.0, 240.0)); flutterView.devicePixelRatio = 3.0; flutterView.physicalSize = const Size(300, 300); binding.handleMetricsChanged(); expect(view.configuration.devicePixelRatio, 3.0); - expect(view.configuration.constraints.isTight, isTrue); - expect(view.configuration.constraints.minWidth, 100.0); - expect(view.configuration.constraints.minHeight, 100.0); + expect(view.configuration.size, const Size(100.0, 100.0)); binding.removeRenderView(view); }); @@ -187,8 +183,6 @@ class FakeFlutterView extends Fake implements FlutterView { @override Size physicalSize; @override - ViewConstraints get physicalConstraints => ViewConstraints.tight(physicalSize); - @override ViewPadding padding; List renderedScenes = []; diff --git a/packages/flutter/test/rendering/view_test.dart b/packages/flutter/test/rendering/view_test.dart index 17bd70e5f8..9caed8c544 100644 --- a/packages/flutter/test/rendering/view_test.dart +++ b/packages/flutter/test/rendering/view_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show ViewConstraints; - import 'package:flutter/rendering.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -18,14 +16,14 @@ void main() { Size size = const Size(20, 20), double devicePixelRatio = 2.0, }) { - return ViewConfiguration(constraints: ViewConstraints.tight(size), devicePixelRatio: devicePixelRatio); + return ViewConfiguration(size: size, devicePixelRatio: devicePixelRatio); } group('RenderView', () { test('accounts for device pixel ratio in paintBounds', () { layout(RenderAspectRatio(aspectRatio: 1.0)); pumpFrame(); - final Size logicalSize = TestRenderingFlutterBinding.instance.renderView.size; + final Size logicalSize = TestRenderingFlutterBinding.instance.renderView.configuration.size; final double devicePixelRatio = TestRenderingFlutterBinding.instance.renderView.configuration.devicePixelRatio; final Size physicalSize = logicalSize * devicePixelRatio; expect(TestRenderingFlutterBinding.instance.renderView.paintBounds, Offset.zero & physicalSize); @@ -128,38 +126,11 @@ void main() { final RenderView view = RenderView( view: RendererBinding.instance.platformDispatcher.views.single, ); - view.configuration = ViewConfiguration(constraints: ViewConstraints.tight(const Size(100, 200)), devicePixelRatio: 3.0); - view.configuration = ViewConfiguration(constraints: ViewConstraints.tight(const Size(200, 300)), devicePixelRatio: 2.0); + view.configuration = const ViewConfiguration(size: Size(100, 200), devicePixelRatio: 3.0); + view.configuration = const ViewConfiguration(size: Size(200, 300), devicePixelRatio: 2.0); PipelineOwner().rootNode = view; view.prepareInitialFrame(); }); - - test('Constraints are derived from configuration', () { - const ViewConfiguration config = ViewConfiguration( - constraints: ViewConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4), - devicePixelRatio: 3.0, - ); - const BoxConstraints constraints = BoxConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4); - - // Configuration set via setter. - final RenderView view = RenderView( - view: RendererBinding.instance.platformDispatcher.views.single, - ); - expect(() => view.constraints, throwsA(isA().having( - (StateError e) => e.message, - 'message', - contains('RenderView has not been given a configuration yet'), - ))); - view.configuration = config; - expect(view.constraints, constraints); - - // Configuration set in constructor. - final RenderView view2 = RenderView( - view: RendererBinding.instance.platformDispatcher.views.single, - configuration: config, - ); - expect(view2.constraints, constraints); - }); } const Color orange = Color(0xFFFF9000); diff --git a/packages/flutter/test/widgets/independent_widget_layout_test.dart b/packages/flutter/test/widgets/independent_widget_layout_test.dart index 3b89a47680..e35c5dc768 100644 --- a/packages/flutter/test/widgets/independent_widget_layout_test.dart +++ b/packages/flutter/test/widgets/independent_widget_layout_test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show FlutterView, ViewConstraints; +import 'dart:ui' show FlutterView; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; @@ -36,7 +36,7 @@ class ScheduledFrameTrackingBindings extends AutomatedTestWidgetsFlutterBinding class OffscreenRenderView extends RenderView { OffscreenRenderView({required super.view}) : super( - configuration: ViewConfiguration(constraints: ViewConstraints.tight(_kTestViewSize)), + configuration: const ViewConfiguration(size: _kTestViewSize), ); @override diff --git a/packages/flutter/test/widgets/keep_alive_test.dart b/packages/flutter/test/widgets/keep_alive_test.dart index ba87c62ba5..c44843916d 100644 --- a/packages/flutter/test/widgets/keep_alive_test.dart +++ b/packages/flutter/test/widgets/keep_alive_test.dart @@ -218,8 +218,7 @@ void main() { ' │ debug mode enabled - ${Platform.operatingSystem}\n' ' │ view size: Size(2400.0, 1800.0) (in physical pixels)\n' ' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n' - ' │ configuration: ViewConstraints(w=800.0, h=600.0) at 3.0x (in\n' - ' │ logical pixels)\n' + ' │ configuration: Size(800.0, 600.0) at 3.0x (in logical pixels)\n' ' │\n' ' └─child: RenderRepaintBoundary#00000\n' ' │ needs compositing\n' @@ -393,8 +392,7 @@ void main() { ' │ debug mode enabled - ${Platform.operatingSystem}\n' ' │ view size: Size(2400.0, 1800.0) (in physical pixels)\n' ' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n' - ' │ configuration: ViewConstraints(w=800.0, h=600.0) at 3.0x (in\n' - ' │ logical pixels)\n' + ' │ configuration: Size(800.0, 600.0) at 3.0x (in logical pixels)\n' ' │\n' ' └─child: RenderRepaintBoundary#00000\n' ' │ needs compositing\n' diff --git a/packages/flutter/test/widgets/view_test.dart b/packages/flutter/test/widgets/view_test.dart index bd3a5b828d..612ca66b81 100644 --- a/packages/flutter/test/widgets/view_test.dart +++ b/packages/flutter/test/widgets/view_test.dart @@ -450,68 +450,6 @@ void main() { }); expect(children, isNot(contains(rawViewOwner))); }); - - testWidgetsWithLeakTracking('RenderView does not use size of child if constraints are tight', (WidgetTester tester) async { - const Size physicalSize = Size(300, 600); - final Size logicalSize = physicalSize / tester.view.devicePixelRatio; - tester.view.physicalConstraints = ViewConstraints.tight(physicalSize); - await tester.pumpWidget(const Placeholder()); - - final RenderView renderView = tester.renderObject(find.byType(View)); - expect(renderView.constraints, BoxConstraints.tight(logicalSize)); - expect(renderView.size, logicalSize); - - final RenderBox child = renderView.child!; - expect(child.constraints, BoxConstraints.tight(logicalSize)); - expect(child.debugCanParentUseSize, isFalse); - expect(child.size, logicalSize); - }); - - testWidgetsWithLeakTracking('RenderView sizes itself to child if constraints allow it (unconstrained)', (WidgetTester tester) async { - const Size size = Size(300, 600); - tester.view.physicalConstraints = const ViewConstraints(); // unconstrained - await tester.pumpWidget(SizedBox.fromSize(size: size)); - - final RenderView renderView = tester.renderObject(find.byType(View)); - expect(renderView.constraints, const BoxConstraints()); - expect(renderView.size, size); - - final RenderBox child = renderView.child!; - expect(child.constraints, const BoxConstraints()); - expect(child.debugCanParentUseSize, isTrue); - expect(child.size, size); - }); - - testWidgetsWithLeakTracking('RenderView sizes itself to child if constraints allow it (constrained)', (WidgetTester tester) async { - const Size size = Size(30, 60); - const ViewConstraints viewConstraints = ViewConstraints(maxWidth: 333, maxHeight: 666); - final BoxConstraints boxConstraints = BoxConstraints.fromViewConstraints(viewConstraints / tester.view.devicePixelRatio); - tester.view.physicalConstraints = viewConstraints; - await tester.pumpWidget(SizedBox.fromSize(size: size)); - - final RenderView renderView = tester.renderObject(find.byType(View)); - expect(renderView.constraints, boxConstraints); - expect(renderView.size, size); - - final RenderBox child = renderView.child!; - expect(child.constraints, boxConstraints); - expect(child.debugCanParentUseSize, isTrue); - expect(child.size, size); - }); - - testWidgetsWithLeakTracking('RenderView respects constraints when child wants to be bigger than allowed', (WidgetTester tester) async { - const Size size = Size(3000, 6000); - const ViewConstraints viewConstraints = ViewConstraints(maxWidth: 300, maxHeight: 600); - tester.view.physicalConstraints = viewConstraints; - await tester.pumpWidget(SizedBox.fromSize(size: size)); - - final RenderView renderView = tester.renderObject(find.byType(View)); - expect(renderView.size, const Size(100, 200)); // viewConstraints.biggest / devicePixelRatio - - final RenderBox child = renderView.child!; - expect(child.debugCanParentUseSize, isTrue); - expect(child.size, const Size(100, 200)); - }); } Future pumpWidgetWithoutViewWrapper({required WidgetTester tester, required Widget widget}) { diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index 79b30542dd..b0da570651 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_test.dart @@ -4696,14 +4696,7 @@ class _TestWidgetInspectorService extends TestWidgetInspectorService { expect(renderObject!['description'], contains('RenderView')); expect(result['parentRenderElement'], isNull); - - final Map? constraints = result['constraints'] as Map?; - expect(constraints, isNotNull); - expect(constraints!['type'], equals('BoxConstraints')); - expect(constraints['minWidth'], equals('800.0')); - expect(constraints['minHeight'], equals('600.0')); - expect(constraints['maxWidth'], equals('800.0')); - expect(constraints['maxHeight'], equals('600.0')); + expect(result['constraints'], isNull); expect(result['isBox'], isNull); final Map? size = result['size'] as Map?; diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index e059581bf4..93a0dd59b2 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -560,7 +560,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase final FlutterView view = renderView.flutterView; if (_surfaceSize != null && view == platformDispatcher.implicitView) { return ViewConfiguration( - constraints: ui.ViewConstraints.tight(_surfaceSize!), + size: _surfaceSize!, devicePixelRatio: view.devicePixelRatio, ); } @@ -1832,7 +1832,7 @@ class LiveTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { final Map? pointerIdToRecord = _renderViewToPointerIdToPointerRecord[renderView]; if (pointerIdToRecord != null && pointerIdToRecord.isNotEmpty) { - final double radius = renderView.size.shortestSide * 0.05; + final double radius = renderView.configuration.size.shortestSide * 0.05; final Path path = Path() ..addOval(Rect.fromCircle(center: Offset.zero, radius: radius)) ..moveTo(0.0, -radius * 2.0) @@ -2116,10 +2116,9 @@ class TestViewConfiguration extends ViewConfiguration { /// Creates a [TestViewConfiguration] with the given size and view. /// /// The [size] defaults to 800x600. - TestViewConfiguration.fromView({required ui.FlutterView view, Size size = _kDefaultTestViewportSize}) + TestViewConfiguration.fromView({required ui.FlutterView view, super.size = _kDefaultTestViewportSize}) : _paintMatrix = _getMatrix(size, view.devicePixelRatio, view), - _physicalSize = view.physicalSize, - super(devicePixelRatio: view.devicePixelRatio, constraints: ui.ViewConstraints.tight(size)); + super(devicePixelRatio: view.devicePixelRatio); static Matrix4 _getMatrix(Size size, double devicePixelRatio, ui.FlutterView window) { final double inverseRatio = devicePixelRatio / window.devicePixelRatio; @@ -2150,11 +2149,6 @@ class TestViewConfiguration extends ViewConfiguration { @override Matrix4 toMatrix() => _paintMatrix.clone(); - final Size _physicalSize; - - @override - Size toPhysicalSize(Size logicalSize) => _physicalSize; - @override String toString() => 'TestViewConfiguration'; } diff --git a/packages/flutter_test/lib/src/window.dart b/packages/flutter_test/lib/src/window.dart index afad65493f..918949adc1 100644 --- a/packages/flutter_test/lib/src/window.dart +++ b/packages/flutter_test/lib/src/window.dart @@ -751,9 +751,6 @@ class TestFlutterView implements FlutterView { /// can only be set in a test environment to emulate different view /// configurations. A standard [FlutterView] is not mutable from the framework. /// - /// Setting this value also sets [physicalConstraints] to tight constraints - /// based on the given size. - /// /// See also: /// /// * [FlutterView.physicalSize] for the standard implementation @@ -764,39 +761,12 @@ class TestFlutterView implements FlutterView { Size? _physicalSize; set physicalSize(Size value) { _physicalSize = value; - // For backwards compatibility the constraints are set based on the provided size. - physicalConstraints = ViewConstraints.tight(value); - } - - /// Resets [physicalSize] (and implicitly also the [physicalConstraints]) to - /// the default value for this view. - void resetPhysicalSize() { - _physicalSize = null; - resetPhysicalConstraints(); - } - - /// The physical constraints to use for this test. - /// - /// Defaults to the value provided by [FlutterView.physicalConstraints]. This - /// can only be set in a test environment to emulate different view - /// configurations. A standard [FlutterView] is not mutable from the framework. - /// - /// See also: - /// - /// * [FlutterView.physicalConstraints] for the standard implementation - /// * [physicalConstraints] to reset this value specifically - /// * [reset] to reset all test values for this view - @override - ViewConstraints get physicalConstraints => _physicalConstraints ?? _view.physicalConstraints; - ViewConstraints? _physicalConstraints; - set physicalConstraints(ViewConstraints value) { - _physicalConstraints = value; platformDispatcher.onMetricsChanged?.call(); } - /// Resets [physicalConstraints] to the default value for this view. - void resetPhysicalConstraints() { - _physicalConstraints = null; + /// Resets [physicalSize] to the default value for this view. + void resetPhysicalSize() { + _physicalSize = null; platformDispatcher.onMetricsChanged?.call(); } @@ -905,7 +875,8 @@ class TestFlutterView implements FlutterView { @override void render(Scene scene, {Size? size}) { - _view.render(scene, size: size); + // TODO(goderbauer): Wire through size after https://github.com/flutter/engine/pull/48090 rolled in. + _view.render(scene); } @override @@ -930,7 +901,6 @@ class TestFlutterView implements FlutterView { resetDisplayFeatures(); resetPadding(); resetPhysicalSize(); - // resetPhysicalConstraints is implicitly called by resetPhysicalSize. resetSystemGestureInsets(); resetViewInsets(); resetViewPadding(); @@ -1667,7 +1637,8 @@ class TestWindow implements SingletonFlutterWindow { ) @override void render(Scene scene, {Size? size}) { - _view.render(scene, size: size); + // TODO(goderbauer): Wire through size after https://github.com/flutter/engine/pull/48090 rolled in. + _view.render(scene); } @Deprecated( diff --git a/packages/flutter_test/test/view_test.dart b/packages/flutter_test/test/view_test.dart index 4d29996acd..f6801864e8 100644 --- a/packages/flutter_test/test/view_test.dart +++ b/packages/flutter_test/test/view_test.dart @@ -124,19 +124,6 @@ void main() { ); }); - testWidgets('faking physicalSize fakes physicalConstraints', (WidgetTester tester) async { - const Size fakeSize = Size(50, 50); - verifyPropertyFaked( - tester: tester, - realValue: trueImplicitView().physicalConstraints, - fakeValue: ViewConstraints.tight(fakeSize), - propertyRetriever: () => boundImplicitView().physicalConstraints, - propertyFaker: (_, __) { - tester.view.physicalSize = fakeSize; - }, - ); - }); - testWidgets('can reset physicalSize', (WidgetTester tester) async { verifyPropertyReset( tester: tester, @@ -151,47 +138,6 @@ void main() { ); }); - testWidgets('resetting physicalSize resets physicalConstraints', (WidgetTester tester) async { - const Size fakeSize = Size(50, 50); - verifyPropertyReset( - tester: tester, - fakeValue: ViewConstraints.tight(fakeSize), - propertyRetriever: () => boundImplicitView().physicalConstraints, - propertyResetter: () { - tester.view.resetPhysicalSize(); - }, - propertyFaker: (_) { - tester.view.physicalSize = fakeSize; - }, - ); - }); - - testWidgets('can fake physicalConstraints', (WidgetTester tester) async { - verifyPropertyFaked( - tester: tester, - realValue: trueImplicitView().physicalConstraints, - fakeValue: const ViewConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4), - propertyRetriever: () => boundImplicitView().physicalConstraints, - propertyFaker: (_, ViewConstraints fakeValue) { - tester.view.physicalConstraints = fakeValue; - }, - ); - }); - - testWidgets('can reset physicalConstraints', (WidgetTester tester) async { - verifyPropertyReset( - tester: tester, - fakeValue: const ViewConstraints(minWidth: 1, maxWidth: 2, minHeight: 3, maxHeight: 4), - propertyRetriever: () => boundImplicitView().physicalConstraints, - propertyResetter: () { - tester.view.resetPhysicalConstraints(); - }, - propertyFaker: (ViewConstraints fakeValue) { - tester.view.physicalConstraints = fakeValue; - }, - ); - }); - testWidgets('can fake systemGestureInsets', (WidgetTester tester) async { verifyPropertyFaked( tester: tester, diff --git a/packages/flutter_test/test/widget_tester_live_device_test.dart b/packages/flutter_test/test/widget_tester_live_device_test.dart index 18c151e9bd..c6468a2f47 100644 --- a/packages/flutter_test/test/widget_tester_live_device_test.dart +++ b/packages/flutter_test/test/widget_tester_live_device_test.dart @@ -83,7 +83,7 @@ No widgets found at Offset(1.0, 1.0). ), ); - final Size originalSize = tester.binding.renderView.size; // ignore: deprecated_member_use + final Size originalSize = tester.binding.createViewConfigurationFor(tester.binding.renderView).size; // ignore: deprecated_member_use await tester.binding.setSurfaceSize(const Size(2000, 1800)); try { await tester.pump();