Skip to content

Commit

Permalink
Implement CheckmarkableChipAttributes on ChoiceChip (#124743)
Browse files Browse the repository at this point in the history
  • Loading branch information
9oya authored Apr 20, 2023
1 parent d85e2fb commit 0c7bc2f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/material/chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ abstract interface class DeletableChipAttributes {
/// * [InputChip], a chip that represents a complex piece of information, such
/// as an entity (person, place, or thing) or conversational text, in a
/// compact form.
/// * [ChoiceChip], allows a single selection from a set of options. Choice
/// chips contain related descriptive text or categories.
/// * [FilterChip], uses tags or descriptive words as a way to filter content.
/// * <https://material.io/design/components/chips.html>
abstract interface class CheckmarkableChipAttributes {
Expand Down
10 changes: 9 additions & 1 deletion packages/flutter/lib/src/material/choice_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ChoiceChip extends StatelessWidget
implements
ChipAttributes,
SelectableChipAttributes,
CheckmarkableChipAttributes,
DisabledChipAttributes {
/// Create a chip that acts like a radio button.
///
Expand Down Expand Up @@ -84,6 +85,8 @@ class ChoiceChip extends StatelessWidget
this.surfaceTintColor,
this.iconTheme,
this.selectedShadowColor,
this.showCheckmark,
this.checkmarkColor,
this.avatarBorder = const CircleBorder(),
}) : assert(pressElevation == null || pressElevation >= 0.0),
assert(elevation == null || elevation >= 0.0);
Expand Down Expand Up @@ -135,6 +138,10 @@ class ChoiceChip extends StatelessWidget
@override
final Color? selectedShadowColor;
@override
final bool? showCheckmark;
@override
final Color? checkmarkColor;
@override
final ShapeBorder avatarBorder;
@override
final IconThemeData? iconTheme;
Expand All @@ -158,7 +165,8 @@ class ChoiceChip extends StatelessWidget
onSelected: onSelected,
pressElevation: pressElevation,
selected: selected,
showCheckmark: Theme.of(context).useMaterial3,
showCheckmark: showCheckmark ?? chipTheme.showCheckmark ?? Theme.of(context).useMaterial3,
checkmarkColor: checkmarkColor,
tooltip: tooltip,
side: side,
shape: shape,
Expand Down
31 changes: 31 additions & 0 deletions packages/flutter/test/material/choice_chip_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,35 @@ void main() {
final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.iconTheme, iconTheme);
});

testWidgets('ChoiceChip passes showCheckmark from ChipTheme to RawChip', (WidgetTester tester) async {
const bool showCheckmark = false;
await tester.pumpWidget(wrapForChip(
child: const ChipTheme(
data: ChipThemeData(
showCheckmark: showCheckmark,
),
child: ChoiceChip(
label: Text('Test'),
selected: true,
),
)));
final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.showCheckmark, showCheckmark);
});

testWidgets('ChoiceChip passes checkmark properties to RawChip', (WidgetTester tester) async {
const bool showCheckmark = false;
const Color checkmarkColor = Color(0xff0000ff);
await tester.pumpWidget(wrapForChip(
child: const ChoiceChip(
label: Text('Test'),
selected: true,
showCheckmark: showCheckmark,
checkmarkColor: checkmarkColor,
)));
final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.showCheckmark, showCheckmark);
expect(rawChip.checkmarkColor, checkmarkColor);
});
}

0 comments on commit 0c7bc2f

Please sign in to comment.