mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Implement CheckmarkableChipAttributes on ChoiceChip (#124743)
This commit is contained in:
parent
d85e2fb810
commit
0c7bc2f9c9
@ -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 {
|
||||
|
||||
@ -52,6 +52,7 @@ class ChoiceChip extends StatelessWidget
|
||||
implements
|
||||
ChipAttributes,
|
||||
SelectableChipAttributes,
|
||||
CheckmarkableChipAttributes,
|
||||
DisabledChipAttributes {
|
||||
/// Create a chip that acts like a radio button.
|
||||
///
|
||||
@ -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);
|
||||
@ -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;
|
||||
@ -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,
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user