Unverified Commit f22043e2 authored by rami-a's avatar rami-a Committed by GitHub

Prevent crash when calling lerp for IconThemeData with null arguments (#26592)

The lerp method for IconThemeData was not doing anything to prevent exceptions when null arguments are used. This change fixes that and adds a test for it.
parent 14f48668
......@@ -72,9 +72,9 @@ class IconThemeData extends Diagnosticable {
static IconThemeData lerp(IconThemeData a, IconThemeData b, double t) {
assert(t != null);
return IconThemeData(
color: Color.lerp(a.color, b.color, t),
opacity: ui.lerpDouble(a.opacity, b.opacity, t),
size: ui.lerpDouble(a.size, b.size, t),
color: Color.lerp(a?.color, b?.color, t),
opacity: ui.lerpDouble(a?.opacity, b?.opacity, t),
size: ui.lerpDouble(a?.size, b?.size, t),
);
}
......
......@@ -14,8 +14,33 @@ void main() {
expect(data.hashCode, equals(data.copyWith().hashCode));
final IconThemeData lerped = IconThemeData.lerp(data, const IconThemeData.fallback(), 0.25);
expect(lerped.color, equals(Color.lerp(const Color(0xAAAAAAAA), const Color(0xFF000000), 0.25)));
expect(lerped.opacity, equals(0.625));
expect(lerped.size, equals(18.0));
expect(lerped.color, const Color(0xBF7F7F7F));
expect(lerped.opacity, 0.625);
expect(lerped.size, 18.0);
});
test('IconThemeData lerp with first null', () {
const IconThemeData data = IconThemeData(color: Color(0xFFFFFFFF), opacity: 1.0, size: 16.0);
final IconThemeData lerped = IconThemeData.lerp(null, data, 0.25);
expect(lerped.color, const Color(0x40FFFFFF));
expect(lerped.opacity, 0.25);
expect(lerped.size, 4.0);
});
test('IconThemeData lerp with second null', () {
const IconThemeData data = IconThemeData(color: Color(0xFFFFFFFF), opacity: 1.0, size: 16.0);
final IconThemeData lerped = IconThemeData.lerp(data, null, 0.25);
expect(lerped.color, const Color(0xBFFFFFFF));
expect(lerped.opacity, 0.75);
expect(lerped.size, 12.0);
});
test('IconThemeData lerp with both null', () {
final IconThemeData lerped = IconThemeData.lerp(null, null, 0.25);
expect(lerped.color, null);
expect(lerped.opacity, null);
expect(lerped.size, null);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment