Remove incorrect non-nullable assumption from ShapeDecoration.lerp (#129298)

Fixes https://github.com/flutter/flutter/issues/129299
This commit is contained in:
Pierre-Louis 2023-06-21 23:34:58 +02:00 committed by GitHub
parent 16eb4f2c08
commit 28ca523ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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)!,
);

View File

@ -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());