mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix Chip highlight color isn't drawn on top of the background color (#124673)
This commit is contained in:
parent
7424f3448d
commit
15cb1f84d7
@ -14,6 +14,7 @@ import 'colors.dart';
|
||||
import 'constants.dart';
|
||||
import 'debug.dart';
|
||||
import 'icons.dart';
|
||||
import 'ink_decoration.dart';
|
||||
import 'ink_well.dart';
|
||||
import 'material.dart';
|
||||
import 'material_localizations.dart';
|
||||
@ -1210,7 +1211,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
|
||||
child: AnimatedBuilder(
|
||||
animation: Listenable.merge(<Listenable>[selectController, enableController]),
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Container(
|
||||
return Ink(
|
||||
decoration: ShapeDecoration(
|
||||
shape: resolvedShape,
|
||||
color: _getBackgroundColor(theme, chipTheme, chipDefaults),
|
||||
|
@ -57,7 +57,7 @@ dynamic getRenderChip(WidgetTester tester) {
|
||||
if (!tester.any(findRenderChipElement())) {
|
||||
return null;
|
||||
}
|
||||
final Element element = tester.element(findRenderChipElement());
|
||||
final Element element = tester.element(findRenderChipElement().first);
|
||||
return element.renderObject;
|
||||
}
|
||||
|
||||
@ -3284,6 +3284,55 @@ void main() {
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('Chip background color and shape are drawn on Ink', (WidgetTester tester) async {
|
||||
const Color backgroundColor = Color(0xff00ff00);
|
||||
const OutlinedBorder shape = ContinuousRectangleBorder();
|
||||
|
||||
await tester.pumpWidget(wrapForChip(
|
||||
child: const RawChip(
|
||||
label: Text('text'),
|
||||
backgroundColor: backgroundColor,
|
||||
shape: shape,
|
||||
),
|
||||
));
|
||||
|
||||
final Ink ink = tester.widget(find.descendant(
|
||||
of: find.byType(RawChip),
|
||||
matching: find.byType(Ink),
|
||||
));
|
||||
final ShapeDecoration decoration = ink.decoration! as ShapeDecoration;
|
||||
expect(decoration.color, backgroundColor);
|
||||
expect(decoration.shape, shape);
|
||||
});
|
||||
|
||||
testWidgets('Chip highlight color is drawn on top of the backgroundColor', (WidgetTester tester) async {
|
||||
final FocusNode focusNode = FocusNode(debugLabel: 'RawChip');
|
||||
tester.binding.focusManager.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
|
||||
const Color backgroundColor = Color(0xff00ff00);
|
||||
|
||||
await tester.pumpWidget(wrapForChip(
|
||||
child: RawChip(
|
||||
label: const Text('text'),
|
||||
backgroundColor: backgroundColor,
|
||||
autofocus: true,
|
||||
focusNode: focusNode,
|
||||
onPressed: () {},
|
||||
),
|
||||
));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(focusNode.hasPrimaryFocus, isTrue);
|
||||
expect(
|
||||
find.byType(Material).last,
|
||||
paints
|
||||
// Background color is drawn first.
|
||||
..rrect(color: backgroundColor)
|
||||
// Highlight color is drawn on top of the background color.
|
||||
..rect(color: const Color(0x1f000000)),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
class _MaterialStateOutlinedBorder extends StadiumBorder implements MaterialStateOutlinedBorder {
|
||||
|
Loading…
Reference in New Issue
Block a user