Skip to content

Commit 73124dc

Browse files
authored
Fix ListTileThemeData.copyWith doesn't override correct properties (#119738)
1 parent 484d881 commit 73124dc

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ class ListTileThemeData with Diagnosticable {
150150
iconColor: iconColor ?? this.iconColor,
151151
textColor: textColor ?? this.textColor,
152152
titleTextStyle: titleTextStyle ?? this.titleTextStyle,
153-
subtitleTextStyle: titleTextStyle ?? this.subtitleTextStyle,
154-
leadingAndTrailingTextStyle: titleTextStyle ?? this.leadingAndTrailingTextStyle,
153+
subtitleTextStyle: subtitleTextStyle ?? this.subtitleTextStyle,
154+
leadingAndTrailingTextStyle: leadingAndTrailingTextStyle ?? this.leadingAndTrailingTextStyle,
155155
contentPadding: contentPadding ?? this.contentPadding,
156156
tileColor: tileColor ?? this.tileColor,
157157
selectedTileColor: selectedTileColor ?? this.selectedTileColor,

packages/flutter/test/material/list_tile_theme_test.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,65 @@ void main() {
700700
await tester.pumpAndSettle();
701701
expect(iconColor(leadingKey), selectedColor);
702702
});
703+
704+
testWidgets('ListTileThemeData copyWith overrides all properties', (WidgetTester tester) async {
705+
// This is a regression test for https://github.com/flutter/flutter/issues/119734
706+
707+
const ListTileThemeData original = ListTileThemeData(
708+
dense: true,
709+
shape: StadiumBorder(),
710+
style: ListTileStyle.drawer,
711+
selectedColor: Color(0x00000001),
712+
iconColor: Color(0x00000002),
713+
textColor: Color(0x00000003),
714+
titleTextStyle: TextStyle(color: Color(0x00000004)),
715+
subtitleTextStyle: TextStyle(color: Color(0x00000005)),
716+
leadingAndTrailingTextStyle: TextStyle(color: Color(0x00000006)),
717+
contentPadding: EdgeInsets.all(100),
718+
tileColor: Color(0x00000007),
719+
selectedTileColor: Color(0x00000008),
720+
horizontalTitleGap: 200,
721+
minVerticalPadding: 300,
722+
minLeadingWidth: 400,
723+
enableFeedback: true,
724+
);
725+
726+
final ListTileThemeData copy = original.copyWith(
727+
dense: false,
728+
shape: const RoundedRectangleBorder(),
729+
style: ListTileStyle.list,
730+
selectedColor: const Color(0x00000009),
731+
iconColor: const Color(0x0000000A),
732+
textColor: const Color(0x0000000B),
733+
titleTextStyle: const TextStyle(color: Color(0x0000000C)),
734+
subtitleTextStyle: const TextStyle(color: Color(0x0000000D)),
735+
leadingAndTrailingTextStyle: const TextStyle(color: Color(0x0000000E)),
736+
contentPadding: const EdgeInsets.all(500),
737+
tileColor: const Color(0x0000000F),
738+
selectedTileColor: const Color(0x00000010),
739+
horizontalTitleGap: 600,
740+
minVerticalPadding: 700,
741+
minLeadingWidth: 800,
742+
enableFeedback: false,
743+
);
744+
745+
expect(copy.dense, false);
746+
expect(copy.shape, const RoundedRectangleBorder());
747+
expect(copy.style, ListTileStyle.list);
748+
expect(copy.selectedColor, const Color(0x00000009));
749+
expect(copy.iconColor, const Color(0x0000000A));
750+
expect(copy.textColor, const Color(0x0000000B));
751+
expect(copy.titleTextStyle, const TextStyle(color: Color(0x0000000C)));
752+
expect(copy.subtitleTextStyle, const TextStyle(color: Color(0x0000000D)));
753+
expect(copy.leadingAndTrailingTextStyle, const TextStyle(color: Color(0x0000000E)));
754+
expect(copy.contentPadding, const EdgeInsets.all(500));
755+
expect(copy.tileColor, const Color(0x0000000F));
756+
expect(copy.selectedTileColor, const Color(0x00000010));
757+
expect(copy.horizontalTitleGap, 600);
758+
expect(copy.minVerticalPadding, 700);
759+
expect(copy.minLeadingWidth, 800);
760+
expect(copy.enableFeedback, false);
761+
});
703762
}
704763

705764
RenderParagraph _getTextRenderObject(WidgetTester tester, String text) {

0 commit comments

Comments
 (0)