From 62414ee44e1095052174c5b76e1d3700ef7d5597 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Wed, 16 Oct 2024 18:14:22 -0700 Subject: [PATCH] Return a valid result for a view with zero width/height in TestViewConfiguration._getMatrix (#157068) Fixes https://github.com/flutter/flutter/issues/157018 --- packages/flutter_test/lib/src/binding.dart | 6 +++++- packages/flutter_test/test/bindings_test.dart | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index fc8d7a6af4..ed5b42983e 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -2181,7 +2181,11 @@ class TestViewConfiguration implements ViewConfiguration { final double desiredWidth = size.width; final double desiredHeight = size.height; double scale, shiftX, shiftY; - if ((actualWidth / actualHeight) > (desiredWidth / desiredHeight)) { + if (desiredWidth == 0.0 || desiredHeight == 0.0) { + scale = 1.0; + shiftX = 0.0; + shiftY = 0.0; + } else if ((actualWidth / actualHeight) > (desiredWidth / desiredHeight)) { scale = actualHeight / desiredHeight; shiftX = (actualWidth - desiredWidth * scale) / 2.0; shiftY = 0.0; diff --git a/packages/flutter_test/test/bindings_test.dart b/packages/flutter_test/test/bindings_test.dart index f2ed74c6e3..5a789fdc32 100644 --- a/packages/flutter_test/test/bindings_test.dart +++ b/packages/flutter_test/test/bindings_test.dart @@ -24,6 +24,12 @@ void main() { // The code below will throw without the default. TestViewConfiguration(size: const Size(1280.0, 800.0)); }); + + test('toMatrix handles zero size', () { + // The code below will throw without the default. + final Matrix4 matrix = TestViewConfiguration(size: Size.zero).toMatrix(); + expect(matrix.storage.every((double x) => x.isFinite), isTrue); + }); }); group(AutomatedTestWidgetsFlutterBinding, () {