Skip to content

Commit 62adfcf

Browse files
authored
Fix RawChip doesn't use ChipTheme.showCheckmark value (flutter#131257)
fixes [`RawChip` doesn't use `ChipThemeData.showCheckmark` value](flutter#119163) ### Description `RawChip.showCheckmark` is nullable yet the constructor falsely assigns a default which breaks `ChipTheme` support. This PR removes the falsely assigned default value. ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @OverRide Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(useMaterial3: true, chipTheme: const ChipThemeData( showCheckmark: false, ) ), home: const Example(), ); } } class Example extends StatelessWidget { const Example({super.key}); @OverRide Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Sample'), ), body: Center( child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ const RawChip( selected: true, label: Text('RawChip'), ), FilterChip( selected: true, label: const Text('RawChip'), onSelected: (bool value) { }, ), ], ), ), ); } } ``` </details> ### Before ![before](https://github.com/flutter/flutter/assets/48603081/c8050c28-d988-4c72-8e0a-6455aa02d119) ### After ![after](https://github.com/flutter/flutter/assets/48603081/d5e83e81-6c12-4594-a2fd-8f113d6c9b54)
1 parent 9def8f6 commit 62adfcf

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ class RawChip extends StatefulWidget
748748
this.surfaceTintColor,
749749
this.iconTheme,
750750
this.selectedShadowColor,
751-
this.showCheckmark = true,
751+
this.showCheckmark,
752752
this.checkmarkColor,
753753
this.avatarBorder = const CircleBorder(),
754754
@Deprecated(

packages/flutter/test/material/chip_theme_test.dart

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void main() {
7171
expect(themeData.brightness, null);
7272
expect(themeData.elevation, null);
7373
expect(themeData.pressElevation, null);
74+
expect(themeData.iconTheme, null);
7475
});
7576

7677
testWidgetsWithLeakTracking('Default ChipThemeData debugFillProperties', (WidgetTester tester) async {
@@ -108,14 +109,15 @@ void main() {
108109
brightness: Brightness.dark,
109110
elevation: 5,
110111
pressElevation: 6,
112+
iconTheme: IconThemeData(color: Color(0xffffff10)),
111113
).debugFillProperties(builder);
112114

113115
final List<String> description = builder.properties
114116
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
115117
.map((DiagnosticsNode node) => node.toString())
116118
.toList();
117119

118-
expect(description, <String>[
120+
expect(description, equalsIgnoringHashCodes(<String>[
119121
'color: MaterialStatePropertyAll(Color(0xfffffff0))',
120122
'backgroundColor: Color(0xfffffff1)',
121123
'deleteIconColor: Color(0xfffffff2)',
@@ -136,7 +138,8 @@ void main() {
136138
'brightness: dark',
137139
'elevation: 5.0',
138140
'pressElevation: 6.0',
139-
]);
141+
'iconTheme: IconThemeData#00000(color: Color(0xffffff10))'
142+
]));
140143
});
141144

142145
testWidgetsWithLeakTracking('Chip uses ThemeData chip theme', (WidgetTester tester) async {
@@ -868,6 +871,63 @@ void main() {
868871
// Enabled & selected chip should have the provided selectedColor.
869872
expect(getMaterialBox(tester), paints..rrect(color: chipTheme.selectedColor));
870873
});
874+
875+
// This is a regression test for https://github.com/flutter/flutter/issues/119163.
876+
testWidgetsWithLeakTracking('RawChip respects checkmark properties from ChipTheme', (WidgetTester tester) async {
877+
Widget buildRawChip({ChipThemeData? chipTheme}) {
878+
return MaterialApp(
879+
theme: ThemeData.light(useMaterial3: false).copyWith(
880+
chipTheme: chipTheme,
881+
),
882+
home: Directionality(
883+
textDirection: TextDirection.ltr,
884+
child: Material(
885+
child: Center(
886+
child: RawChip(
887+
selected: true,
888+
label: const SizedBox(width: 100, height: 100),
889+
onSelected: (bool newValue) { },
890+
),
891+
),
892+
),
893+
),
894+
);
895+
}
896+
897+
// Test that the checkmark is painted.
898+
await tester.pumpWidget(buildRawChip(
899+
chipTheme: const ChipThemeData(
900+
checkmarkColor: Color(0xffff0000),
901+
),
902+
));
903+
904+
RenderBox materialBox = getMaterialBox(tester);
905+
expect(
906+
materialBox,
907+
paints..path(
908+
color: const Color(0xffff0000),
909+
style: PaintingStyle.stroke,
910+
),
911+
);
912+
913+
// Test that the checkmark is not painted when ChipThemeData.showCheckmark is false.
914+
await tester.pumpWidget(buildRawChip(
915+
chipTheme: const ChipThemeData(
916+
showCheckmark: false,
917+
checkmarkColor: Color(0xffff0000),
918+
),
919+
));
920+
await tester.pumpAndSettle();
921+
922+
materialBox = getMaterialBox(tester);
923+
expect(
924+
materialBox,
925+
isNot(paints..path(
926+
color: const Color(0xffff0000),
927+
style: PaintingStyle.stroke,
928+
)),
929+
);
930+
});
871931
}
872932

873933
class _MaterialStateOutlinedBorder extends StadiumBorder implements MaterialStateOutlinedBorder {

0 commit comments

Comments
 (0)