From 28ca523ac28257120a0b6e614caa84d7dd1cf35c Mon Sep 17 00:00:00 2001 From: Pierre-Louis <6655696+guidezpl@users.noreply.github.com> Date: Wed, 21 Jun 2023 23:34:58 +0200 Subject: [PATCH] Remove incorrect non-nullable assumption from `ShapeDecoration.lerp` (#129298) Fixes https://github.com/flutter/flutter/issues/129299 --- packages/flutter/lib/src/painting/shape_decoration.dart | 2 +- packages/flutter/test/painting/shape_decoration_test.dart | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/painting/shape_decoration.dart b/packages/flutter/lib/src/painting/shape_decoration.dart index 9909128b05..20785bced2 100644 --- a/packages/flutter/lib/src/painting/shape_decoration.dart +++ b/packages/flutter/lib/src/painting/shape_decoration.dart @@ -237,7 +237,7 @@ class ShapeDecoration extends Decoration { return ShapeDecoration( color: Color.lerp(a?.color, b?.color, t), gradient: Gradient.lerp(a?.gradient, b?.gradient, t), - image: t < 0.5 ? a!.image : b!.image, // TODO(ianh): cross-fade the image + image: t < 0.5 ? a?.image : b?.image, // TODO(ianh): cross-fade the image shadows: BoxShadow.lerpList(a?.shadows, b?.shadows, t), shape: ShapeBorder.lerp(a?.shape, b?.shape, t)!, ); diff --git a/packages/flutter/test/painting/shape_decoration_test.dart b/packages/flutter/test/painting/shape_decoration_test.dart index 9c6adf10da..402aa70c3b 100644 --- a/packages/flutter/test/painting/shape_decoration_test.dart +++ b/packages/flutter/test/painting/shape_decoration_test.dart @@ -48,6 +48,14 @@ void main() { expect(identical(ShapeDecoration.lerp(shape, shape, 0.5), shape), true); }); + test('ShapeDecoration.lerp null a,b', () { + const Decoration a = ShapeDecoration(shape: CircleBorder()); + const Decoration b = ShapeDecoration(shape: RoundedRectangleBorder()); + expect(Decoration.lerp(a, null, 0.0), a); + expect(Decoration.lerp(null, b, 0.0), b); + expect(Decoration.lerp(null, null, 0.0), null); + }); + test('ShapeDecoration.lerp and hit test', () { const Decoration a = ShapeDecoration(shape: CircleBorder()); const Decoration b = ShapeDecoration(shape: RoundedRectangleBorder());