Skip to content

Commit 0c7bc2f

Browse files
authored
Implement CheckmarkableChipAttributes on ChoiceChip (#124743)
1 parent d85e2fb commit 0c7bc2f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ abstract interface class DeletableChipAttributes {
275275
/// * [InputChip], a chip that represents a complex piece of information, such
276276
/// as an entity (person, place, or thing) or conversational text, in a
277277
/// compact form.
278+
/// * [ChoiceChip], allows a single selection from a set of options. Choice
279+
/// chips contain related descriptive text or categories.
278280
/// * [FilterChip], uses tags or descriptive words as a way to filter content.
279281
/// * <https://material.io/design/components/chips.html>
280282
abstract interface class CheckmarkableChipAttributes {

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ChoiceChip extends StatelessWidget
5252
implements
5353
ChipAttributes,
5454
SelectableChipAttributes,
55+
CheckmarkableChipAttributes,
5556
DisabledChipAttributes {
5657
/// Create a chip that acts like a radio button.
5758
///
@@ -84,6 +85,8 @@ class ChoiceChip extends StatelessWidget
8485
this.surfaceTintColor,
8586
this.iconTheme,
8687
this.selectedShadowColor,
88+
this.showCheckmark,
89+
this.checkmarkColor,
8790
this.avatarBorder = const CircleBorder(),
8891
}) : assert(pressElevation == null || pressElevation >= 0.0),
8992
assert(elevation == null || elevation >= 0.0);
@@ -135,6 +138,10 @@ class ChoiceChip extends StatelessWidget
135138
@override
136139
final Color? selectedShadowColor;
137140
@override
141+
final bool? showCheckmark;
142+
@override
143+
final Color? checkmarkColor;
144+
@override
138145
final ShapeBorder avatarBorder;
139146
@override
140147
final IconThemeData? iconTheme;
@@ -158,7 +165,8 @@ class ChoiceChip extends StatelessWidget
158165
onSelected: onSelected,
159166
pressElevation: pressElevation,
160167
selected: selected,
161-
showCheckmark: Theme.of(context).useMaterial3,
168+
showCheckmark: showCheckmark ?? chipTheme.showCheckmark ?? Theme.of(context).useMaterial3,
169+
checkmarkColor: checkmarkColor,
162170
tooltip: tooltip,
163171
side: side,
164172
shape: shape,

packages/flutter/test/material/choice_chip_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,35 @@ void main() {
132132
final RawChip rawChip = tester.widget(find.byType(RawChip));
133133
expect(rawChip.iconTheme, iconTheme);
134134
});
135+
136+
testWidgets('ChoiceChip passes showCheckmark from ChipTheme to RawChip', (WidgetTester tester) async {
137+
const bool showCheckmark = false;
138+
await tester.pumpWidget(wrapForChip(
139+
child: const ChipTheme(
140+
data: ChipThemeData(
141+
showCheckmark: showCheckmark,
142+
),
143+
child: ChoiceChip(
144+
label: Text('Test'),
145+
selected: true,
146+
),
147+
)));
148+
final RawChip rawChip = tester.widget(find.byType(RawChip));
149+
expect(rawChip.showCheckmark, showCheckmark);
150+
});
151+
152+
testWidgets('ChoiceChip passes checkmark properties to RawChip', (WidgetTester tester) async {
153+
const bool showCheckmark = false;
154+
const Color checkmarkColor = Color(0xff0000ff);
155+
await tester.pumpWidget(wrapForChip(
156+
child: const ChoiceChip(
157+
label: Text('Test'),
158+
selected: true,
159+
showCheckmark: showCheckmark,
160+
checkmarkColor: checkmarkColor,
161+
)));
162+
final RawChip rawChip = tester.widget(find.byType(RawChip));
163+
expect(rawChip.showCheckmark, showCheckmark);
164+
expect(rawChip.checkmarkColor, checkmarkColor);
165+
});
135166
}

0 commit comments

Comments
 (0)