Skip to content

Commit 15cb1f8

Browse files
authored
Fix Chip highlight color isn't drawn on top of the background color (#124673)
1 parent 7424f34 commit 15cb1f8

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'colors.dart';
1414
import 'constants.dart';
1515
import 'debug.dart';
1616
import 'icons.dart';
17+
import 'ink_decoration.dart';
1718
import 'ink_well.dart';
1819
import 'material.dart';
1920
import 'material_localizations.dart';
@@ -1210,7 +1211,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
12101211
child: AnimatedBuilder(
12111212
animation: Listenable.merge(<Listenable>[selectController, enableController]),
12121213
builder: (BuildContext context, Widget? child) {
1213-
return Container(
1214+
return Ink(
12141215
decoration: ShapeDecoration(
12151216
shape: resolvedShape,
12161217
color: _getBackgroundColor(theme, chipTheme, chipDefaults),

packages/flutter/test/material/chip_test.dart

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ dynamic getRenderChip(WidgetTester tester) {
5757
if (!tester.any(findRenderChipElement())) {
5858
return null;
5959
}
60-
final Element element = tester.element(findRenderChipElement());
60+
final Element element = tester.element(findRenderChipElement().first);
6161
return element.renderObject;
6262
}
6363

@@ -3284,6 +3284,55 @@ void main() {
32843284

32853285
expect(tester.takeException(), isNull);
32863286
});
3287+
3288+
testWidgets('Chip background color and shape are drawn on Ink', (WidgetTester tester) async {
3289+
const Color backgroundColor = Color(0xff00ff00);
3290+
const OutlinedBorder shape = ContinuousRectangleBorder();
3291+
3292+
await tester.pumpWidget(wrapForChip(
3293+
child: const RawChip(
3294+
label: Text('text'),
3295+
backgroundColor: backgroundColor,
3296+
shape: shape,
3297+
),
3298+
));
3299+
3300+
final Ink ink = tester.widget(find.descendant(
3301+
of: find.byType(RawChip),
3302+
matching: find.byType(Ink),
3303+
));
3304+
final ShapeDecoration decoration = ink.decoration! as ShapeDecoration;
3305+
expect(decoration.color, backgroundColor);
3306+
expect(decoration.shape, shape);
3307+
});
3308+
3309+
testWidgets('Chip highlight color is drawn on top of the backgroundColor', (WidgetTester tester) async {
3310+
final FocusNode focusNode = FocusNode(debugLabel: 'RawChip');
3311+
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
3312+
const Color backgroundColor = Color(0xff00ff00);
3313+
3314+
await tester.pumpWidget(wrapForChip(
3315+
child: RawChip(
3316+
label: const Text('text'),
3317+
backgroundColor: backgroundColor,
3318+
autofocus: true,
3319+
focusNode: focusNode,
3320+
onPressed: () {},
3321+
),
3322+
));
3323+
3324+
await tester.pumpAndSettle();
3325+
3326+
expect(focusNode.hasPrimaryFocus, isTrue);
3327+
expect(
3328+
find.byType(Material).last,
3329+
paints
3330+
// Background color is drawn first.
3331+
..rrect(color: backgroundColor)
3332+
// Highlight color is drawn on top of the background color.
3333+
..rect(color: const Color(0x1f000000)),
3334+
);
3335+
});
32873336
}
32883337

32893338
class _MaterialStateOutlinedBorder extends StadiumBorder implements MaterialStateOutlinedBorder {

0 commit comments

Comments
 (0)