Skip to content

Commit b34ee07

Browse files
Fix token usages on Regular Chip and Action Chip (#141701)
The regular chip and the action chip templates were referencing non existent M3 design tokens. Fixes flutter/flutter#141288 The `ActionChip` doesn't have any visual difference. Even though the template and file changes, the default `labelStyle` color already uses `onSurface`. For the reviewer, I've changed the `action_chip_test` to expect a color from the colorScheme so that it is more explicit that the color might not be the same as the labelLarge default in the global textTheme, even if for this case the color is the same. The regular `Chip` does have visual differences, in particular, the label and trailing icon colors, which were not following the specification. In order to fix this, the regular chip now is based from the `filter-chip` spec as described in the linked issue. ## Before ![image](https://github.com/flutter/flutter/assets/22084723/d602ef42-625a-4b5c-b63b-c46cb2070d80) ## After ![image](https://github.com/flutter/flutter/assets/22084723/dddb754f-fd29-4c4c-96cc-e7f508219f12)
1 parent ff6c8f5 commit b34ee07

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
lines changed

dev/tools/gen_defaults/generated/used_tokens.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Versions used, v0_162, v0_202, v0_158
22
md.comp.assist-chip.container.shape,
33
md.comp.assist-chip.container.surface-tint-layer.color,
4+
md.comp.assist-chip.disabled.label-text.color,
45
md.comp.assist-chip.elevated.container.elevation,
56
md.comp.assist-chip.elevated.container.shadow-color,
67
md.comp.assist-chip.elevated.disabled.container.color,
@@ -12,6 +13,7 @@ md.comp.assist-chip.flat.disabled.outline.color,
1213
md.comp.assist-chip.flat.disabled.outline.opacity,
1314
md.comp.assist-chip.flat.outline.color,
1415
md.comp.assist-chip.flat.outline.width,
16+
md.comp.assist-chip.label-text.color,
1517
md.comp.assist-chip.label-text.text-style,
1618
md.comp.assist-chip.with-icon.disabled.icon.color,
1719
md.comp.assist-chip.with-icon.icon.color,

dev/tools/gen_defaults/lib/action_chip_template.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
3838
double? get pressElevation => ${elevation("$tokenGroup$elevatedVariant.pressed.container")};
3939
4040
@override
41-
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")};
41+
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")}?.copyWith(
42+
color: isEnabled
43+
? ${color("$tokenGroup.label-text.color")}
44+
: ${color("$tokenGroup.disabled.label-text.color")},
45+
);
4246
4347
@override
4448
MaterialStateProperty<Color?>? get color =>
@@ -60,10 +64,10 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
6064
Color? get surfaceTintColor => ${colorOrTransparent("$tokenGroup.container.surface-tint-layer.color")};
6165
6266
@override
63-
Color? get checkmarkColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
67+
Color? get checkmarkColor => null;
6468
6569
@override
66-
Color? get deleteIconColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
70+
Color? get deleteIconColor => null;
6771
6872
@override
6973
BorderSide? get side => _chipVariant == _ChipVariant.flat

dev/tools/gen_defaults/lib/chip_template.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ChipTemplate extends TokenTemplate {
1010
super.textThemePrefix = '_textTheme.'
1111
});
1212

13-
static const String tokenGroup = 'md.comp.assist-chip';
13+
static const String tokenGroup = 'md.comp.filter-chip';
1414
static const String variant = '.flat';
1515

1616
@override
@@ -29,7 +29,11 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
2929
late final TextTheme _textTheme = Theme.of(context).textTheme;
3030
3131
@override
32-
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")};
32+
TextStyle? get labelStyle => ${textStyle("$tokenGroup.label-text")}?.copyWith(
33+
color: isEnabled
34+
? ${color("$tokenGroup.unselected.label-text.color")}
35+
: ${color("$tokenGroup.disabled.label-text.color")},
36+
);
3337
3438
@override
3539
MaterialStateProperty<Color?>? get color => null; // Subclasses override this getter
@@ -41,21 +45,23 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
4145
Color? get surfaceTintColor => ${colorOrTransparent("$tokenGroup.container.surface-tint-layer.color")};
4246
4347
@override
44-
Color? get checkmarkColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
48+
Color? get checkmarkColor => null;
4549
4650
@override
47-
Color? get deleteIconColor => ${color("$tokenGroup.with-icon.selected.icon.color")};
51+
Color? get deleteIconColor => isEnabled
52+
? ${color("$tokenGroup.with-trailing-icon.unselected.trailing-icon.color")}
53+
: ${color("$tokenGroup.with-trailing-icon.disabled.trailing-icon.color")};
4854
4955
@override
5056
BorderSide? get side => isEnabled
51-
? ${border('$tokenGroup$variant.outline')}
52-
: ${border('$tokenGroup$variant.disabled.outline')};
57+
? ${border('$tokenGroup$variant.unselected.outline')}
58+
: ${border('$tokenGroup$variant.disabled.unselected.outline')};
5359
5460
@override
5561
IconThemeData? get iconTheme => IconThemeData(
5662
color: isEnabled
57-
? ${color("$tokenGroup.with-icon.icon.color")}
58-
: ${color("$tokenGroup.with-icon.disabled.icon.color")},
63+
? ${color("$tokenGroup.with-leading-icon.unselected.leading-icon.color")}
64+
: ${color("$tokenGroup.with-leading-icon.disabled.leading-icon.color")},
5965
size: ${getToken("$tokenGroup.with-icon.icon.size")},
6066
);
6167

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,11 @@ class _ActionChipDefaultsM3 extends ChipThemeData {
259259
double? get pressElevation => 1.0;
260260

261261
@override
262-
TextStyle? get labelStyle => _textTheme.labelLarge;
262+
TextStyle? get labelStyle => _textTheme.labelLarge?.copyWith(
263+
color: isEnabled
264+
? _colors.onSurface
265+
: _colors.onSurface,
266+
);
263267

264268
@override
265269
MaterialStateProperty<Color?>? get color =>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,11 @@ class _ChipDefaultsM3 extends ChipThemeData {
22792279
late final TextTheme _textTheme = Theme.of(context).textTheme;
22802280

22812281
@override
2282-
TextStyle? get labelStyle => _textTheme.labelLarge;
2282+
TextStyle? get labelStyle => _textTheme.labelLarge?.copyWith(
2283+
color: isEnabled
2284+
? _colors.onSurfaceVariant
2285+
: _colors.onSurface,
2286+
);
22832287

22842288
@override
22852289
MaterialStateProperty<Color?>? get color => null; // Subclasses override this getter
@@ -2294,7 +2298,9 @@ class _ChipDefaultsM3 extends ChipThemeData {
22942298
Color? get checkmarkColor => null;
22952299

22962300
@override
2297-
Color? get deleteIconColor => null;
2301+
Color? get deleteIconColor => isEnabled
2302+
? _colors.onSurfaceVariant
2303+
: _colors.onSurface;
22982304

22992305
@override
23002306
BorderSide? get side => isEnabled

packages/flutter/test/material/action_chip_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void main() {
155155
// Test default label style.
156156
expect(
157157
getLabelStyle(tester, label).style.color!.value,
158-
theme.textTheme.labelLarge!.color!.value,
158+
theme.colorScheme.onSurface.value,
159159
);
160160

161161
Material chipMaterial = getMaterial(tester);
@@ -229,7 +229,7 @@ void main() {
229229
// Test default label style.
230230
expect(
231231
getLabelStyle(tester, label).style.color!.value,
232-
theme.textTheme.labelLarge!.color!.value,
232+
theme.colorScheme.onSurface.value,
233233
);
234234

235235
Material chipMaterial = getMaterial(tester);

packages/flutter/test/material/chip_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ void main() {
333333
expect(getIconData(tester).size, 18);
334334

335335
TextStyle labelStyle = getLabelStyle(tester, 'Chip A').style;
336-
expect(labelStyle.color, textTheme.labelLarge?.color);
336+
expect(labelStyle.color, lightTheme.colorScheme.onSurfaceVariant);
337337
expect(labelStyle.fontFamily, textTheme.labelLarge?.fontFamily);
338338
expect(labelStyle.fontFamilyFallback, textTheme.labelLarge?.fontFamilyFallback);
339339
expect(labelStyle.fontFeatures, textTheme.labelLarge?.fontFeatures);
@@ -361,7 +361,7 @@ void main() {
361361
expect(getIconData(tester).size, 18);
362362

363363
labelStyle = getLabelStyle(tester, 'Chip A').style;
364-
expect(labelStyle.color, textTheme.labelLarge?.color);
364+
expect(labelStyle.color, darkTheme.colorScheme.onSurfaceVariant);
365365
expect(labelStyle.fontFamily, textTheme.labelLarge?.fontFamily);
366366
expect(labelStyle.fontFamilyFallback, textTheme.labelLarge?.fontFamilyFallback);
367367
expect(labelStyle.fontFeatures, textTheme.labelLarge?.fontFeatures);

0 commit comments

Comments
 (0)