Unverified Commit 0c7bc2f9 authored by 9oya's avatar 9oya Committed by GitHub

Implement CheckmarkableChipAttributes on ChoiceChip (#124743)

parent d85e2fb8
...@@ -275,6 +275,8 @@ abstract interface class DeletableChipAttributes { ...@@ -275,6 +275,8 @@ abstract interface class DeletableChipAttributes {
/// * [InputChip], a chip that represents a complex piece of information, such /// * [InputChip], a chip that represents a complex piece of information, such
/// as an entity (person, place, or thing) or conversational text, in a /// as an entity (person, place, or thing) or conversational text, in a
/// compact form. /// 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. /// * [FilterChip], uses tags or descriptive words as a way to filter content.
/// * <https://material.io/design/components/chips.html> /// * <https://material.io/design/components/chips.html>
abstract interface class CheckmarkableChipAttributes { abstract interface class CheckmarkableChipAttributes {
......
...@@ -52,6 +52,7 @@ class ChoiceChip extends StatelessWidget ...@@ -52,6 +52,7 @@ class ChoiceChip extends StatelessWidget
implements implements
ChipAttributes, ChipAttributes,
SelectableChipAttributes, SelectableChipAttributes,
CheckmarkableChipAttributes,
DisabledChipAttributes { DisabledChipAttributes {
/// Create a chip that acts like a radio button. /// Create a chip that acts like a radio button.
/// ///
...@@ -84,6 +85,8 @@ class ChoiceChip extends StatelessWidget ...@@ -84,6 +85,8 @@ class ChoiceChip extends StatelessWidget
this.surfaceTintColor, this.surfaceTintColor,
this.iconTheme, this.iconTheme,
this.selectedShadowColor, this.selectedShadowColor,
this.showCheckmark,
this.checkmarkColor,
this.avatarBorder = const CircleBorder(), this.avatarBorder = const CircleBorder(),
}) : assert(pressElevation == null || pressElevation >= 0.0), }) : assert(pressElevation == null || pressElevation >= 0.0),
assert(elevation == null || elevation >= 0.0); assert(elevation == null || elevation >= 0.0);
...@@ -135,6 +138,10 @@ class ChoiceChip extends StatelessWidget ...@@ -135,6 +138,10 @@ class ChoiceChip extends StatelessWidget
@override @override
final Color? selectedShadowColor; final Color? selectedShadowColor;
@override @override
final bool? showCheckmark;
@override
final Color? checkmarkColor;
@override
final ShapeBorder avatarBorder; final ShapeBorder avatarBorder;
@override @override
final IconThemeData? iconTheme; final IconThemeData? iconTheme;
...@@ -158,7 +165,8 @@ class ChoiceChip extends StatelessWidget ...@@ -158,7 +165,8 @@ class ChoiceChip extends StatelessWidget
onSelected: onSelected, onSelected: onSelected,
pressElevation: pressElevation, pressElevation: pressElevation,
selected: selected, selected: selected,
showCheckmark: Theme.of(context).useMaterial3, showCheckmark: showCheckmark ?? chipTheme.showCheckmark ?? Theme.of(context).useMaterial3,
checkmarkColor: checkmarkColor,
tooltip: tooltip, tooltip: tooltip,
side: side, side: side,
shape: shape, shape: shape,
......
...@@ -132,4 +132,35 @@ void main() { ...@@ -132,4 +132,35 @@ void main() {
final RawChip rawChip = tester.widget(find.byType(RawChip)); final RawChip rawChip = tester.widget(find.byType(RawChip));
expect(rawChip.iconTheme, iconTheme); 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);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment