From 0c7bc2f9c9b25efe950a453d415ff191bfaf94c2 Mon Sep 17 00:00:00 2001 From: 9oya <53330969+9oya@users.noreply.github.com> Date: Fri, 21 Apr 2023 03:43:49 +0900 Subject: [PATCH] Implement CheckmarkableChipAttributes on ChoiceChip (#124743) --- packages/flutter/lib/src/material/chip.dart | 2 ++ .../flutter/lib/src/material/choice_chip.dart | 10 +++++- .../test/material/choice_chip_test.dart | 31 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index 3eeac224f8a3..614856573d2c 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -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. /// * abstract interface class CheckmarkableChipAttributes { diff --git a/packages/flutter/lib/src/material/choice_chip.dart b/packages/flutter/lib/src/material/choice_chip.dart index 436f21842ccd..f8602ea9d748 100644 --- a/packages/flutter/lib/src/material/choice_chip.dart +++ b/packages/flutter/lib/src/material/choice_chip.dart @@ -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, diff --git a/packages/flutter/test/material/choice_chip_test.dart b/packages/flutter/test/material/choice_chip_test.dart index 62506d209acb..5ec884ceb74a 100644 --- a/packages/flutter/test/material/choice_chip_test.dart +++ b/packages/flutter/test/material/choice_chip_test.dart @@ -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); + }); }