Skip to content

Commit a10e295

Browse files
authored
Added identical(a,b) short circuit to Material Library lerp methods (#120829)
1 parent c0b7d2d commit a10e295

File tree

93 files changed

+433
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+433
-51
lines changed

packages/flutter/lib/src/material/app_bar_theme.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ class AppBarTheme with Diagnosticable {
204204
///
205205
/// {@macro dart.ui.shadow.lerp}
206206
static AppBarTheme lerp(AppBarTheme? a, AppBarTheme? b, double t) {
207+
if (identical(a, b) && a != null) {
208+
return a;
209+
}
207210
return AppBarTheme(
208211
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
209212
foregroundColor: Color.lerp(a?.foregroundColor, b?.foregroundColor, t),

packages/flutter/lib/src/material/badge_theme.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class BadgeThemeData with Diagnosticable {
9494

9595
/// Linearly interpolate between two [Badge] themes.
9696
static BadgeThemeData lerp(BadgeThemeData? a, BadgeThemeData? b, double t) {
97+
if (identical(a, b) && a != null) {
98+
return a;
99+
}
97100
return BadgeThemeData(
98101
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
99102
textColor: Color.lerp(a?.textColor, b?.textColor, t),

packages/flutter/lib/src/material/bottom_app_bar_theme.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class BottomAppBarTheme with Diagnosticable {
9494
///
9595
/// {@macro dart.ui.shadow.lerp}
9696
static BottomAppBarTheme lerp(BottomAppBarTheme? a, BottomAppBarTheme? b, double t) {
97+
if (identical(a, b) && a != null) {
98+
return a;
99+
}
97100
return BottomAppBarTheme(
98101
color: Color.lerp(a?.color, b?.color, t),
99102
elevation: lerpDouble(a?.elevation, b?.elevation, t),

packages/flutter/lib/src/material/bottom_navigation_bar_theme.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ class BottomNavigationBarThemeData with Diagnosticable {
174174
///
175175
/// {@macro dart.ui.shadow.lerp}
176176
static BottomNavigationBarThemeData lerp(BottomNavigationBarThemeData? a, BottomNavigationBarThemeData? b, double t) {
177+
if (identical(a, b) && a != null) {
178+
return a;
179+
}
177180
return BottomNavigationBarThemeData(
178181
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),
179182
elevation: lerpDouble(a?.elevation, b?.elevation, t),

packages/flutter/lib/src/material/bottom_sheet_theme.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ class BottomSheetThemeData with Diagnosticable {
118118
///
119119
/// {@macro dart.ui.shadow.lerp}
120120
static BottomSheetThemeData? lerp(BottomSheetThemeData? a, BottomSheetThemeData? b, double t) {
121-
if (a == null && b == null) {
122-
return null;
121+
if (identical(a, b)) {
122+
return a;
123123
}
124124
return BottomSheetThemeData(
125125
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),

packages/flutter/lib/src/material/button_bar_theme.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ class ButtonBarThemeData with Diagnosticable {
146146
///
147147
/// {@macro dart.ui.shadow.lerp}
148148
static ButtonBarThemeData? lerp(ButtonBarThemeData? a, ButtonBarThemeData? b, double t) {
149-
if (a == null && b == null) {
150-
return null;
149+
if (identical(a, b)) {
150+
return a;
151151
}
152152
return ButtonBarThemeData(
153153
alignment: t < 0.5 ? a?.alignment : b?.alignment,

packages/flutter/lib/src/material/button_style.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ class ButtonStyle with Diagnosticable {
492492

493493
/// Linearly interpolate between two [ButtonStyle]s.
494494
static ButtonStyle? lerp(ButtonStyle? a, ButtonStyle? b, double t) {
495-
if (a == null && b == null) {
496-
return null;
495+
if (identical(a, b)) {
496+
return a;
497497
}
498498
return ButtonStyle(
499499
textStyle: MaterialStateProperty.lerp<TextStyle?>(a?.textStyle, b?.textStyle, t, TextStyle.lerp),

packages/flutter/lib/src/material/card_theme.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class CardTheme with Diagnosticable {
114114
///
115115
/// {@macro dart.ui.shadow.lerp}
116116
static CardTheme lerp(CardTheme? a, CardTheme? b, double t) {
117+
if (identical(a, b) && a != null) {
118+
return a;
119+
}
117120
return CardTheme(
118121
clipBehavior: t < 0.5 ? a?.clipBehavior : b?.clipBehavior,
119122
color: Color.lerp(a?.color, b?.color, t),

packages/flutter/lib/src/material/checkbox_theme.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ class CheckboxThemeData with Diagnosticable {
130130
///
131131
/// {@macro dart.ui.shadow.lerp}
132132
static CheckboxThemeData lerp(CheckboxThemeData? a, CheckboxThemeData? b, double t) {
133+
if (identical(a, b) && a != null) {
134+
return a;
135+
}
133136
return CheckboxThemeData(
134137
mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor,
135138
fillColor: MaterialStateProperty.lerp<Color?>(a?.fillColor, b?.fillColor, t, Color.lerp),
@@ -195,6 +198,9 @@ class CheckboxThemeData with Diagnosticable {
195198
if (a == null || b == null) {
196199
return null;
197200
}
201+
if (identical(a, b)) {
202+
return a;
203+
}
198204
return BorderSide.lerp(a, b, t);
199205
}
200206
}

packages/flutter/lib/src/material/chip_theme.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ class ChipThemeData with Diagnosticable {
483483
///
484484
/// {@macro dart.ui.shadow.lerp}
485485
static ChipThemeData? lerp(ChipThemeData? a, ChipThemeData? b, double t) {
486-
if (a == null && b == null) {
487-
return null;
486+
if (identical(a, b)) {
487+
return a;
488488
}
489489
return ChipThemeData(
490490
backgroundColor: Color.lerp(a?.backgroundColor, b?.backgroundColor, t),

0 commit comments

Comments
 (0)