Skip to content

Commit 14f9933

Browse files
authored
[material_ui] Fix SnackBarThemeData.lerp dropping showCloseIcon (#13449)
`SnackBarThemeData.lerp` never passes `showCloseIcon` to the constructor, so a lerped theme always has `showCloseIcon == null`. This shows up during `AnimatedTheme` transitions, where a snack bar loses the close icon its theme asked for. This adds `showCloseIcon` to `lerp` using the same `t < 0.5` switch as the other non-lerpable fields (`behavior`, `dismissDirection`), and a unit test covering both halves of the animation and a null theme on either side. Fixes flutter/flutter#195390 ## Pre-Review Checklist
1 parent 4765bd9 commit 14f9933

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎packages/material_ui/lib/src/snack_bar_theme.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ class SnackBarThemeData with Diagnosticable {
255255
t,
256256
),
257257
dismissDirection: t < 0.5 ? a?.dismissDirection : b?.dismissDirection,
258+
showCloseIcon: t < 0.5 ? a?.showCloseIcon : b?.showCloseIcon,
258259
);
259260
}
260261

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Fixes `SnackBarThemeData.lerp` dropping `showCloseIcon`.
3+
version: patch

‎packages/material_ui/test/snack_bar_theme_test.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ void main() {
1818
expect(identical(SnackBarThemeData.lerp(data, data, 0.5), data), true);
1919
});
2020

21+
test('SnackBarThemeData lerp keeps showCloseIcon', () {
22+
const a = SnackBarThemeData(showCloseIcon: true);
23+
const b = SnackBarThemeData(showCloseIcon: false);
24+
expect(SnackBarThemeData.lerp(a, b, 0.25).showCloseIcon, true);
25+
expect(SnackBarThemeData.lerp(a, b, 0.75).showCloseIcon, false);
26+
expect(SnackBarThemeData.lerp(a, null, 0.25).showCloseIcon, true);
27+
expect(SnackBarThemeData.lerp(null, a, 0.75).showCloseIcon, true);
28+
});
29+
2130
test('SnackBarThemeData null fields by default', () {
2231
const snackBarTheme = SnackBarThemeData();
2332
expect(snackBarTheme.backgroundColor, null);

0 commit comments

Comments
 (0)