mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Make the InkResponse's focus highlight honor the radius parameter (#59117)
This commit is contained in:
parent
cd547c70b2
commit
cb8562e163
@ -41,6 +41,7 @@ class InkHighlight extends InteractiveInkFeature {
|
||||
@required Color color,
|
||||
@required TextDirection textDirection,
|
||||
BoxShape shape = BoxShape.rectangle,
|
||||
double radius,
|
||||
BorderRadius borderRadius,
|
||||
ShapeBorder customBorder,
|
||||
RectCallback rectCallback,
|
||||
@ -51,6 +52,7 @@ class InkHighlight extends InteractiveInkFeature {
|
||||
assert(textDirection != null),
|
||||
assert(fadeDuration != null),
|
||||
_shape = shape,
|
||||
_radius = radius,
|
||||
_borderRadius = borderRadius ?? BorderRadius.zero,
|
||||
_customBorder = customBorder,
|
||||
_textDirection = textDirection,
|
||||
@ -69,6 +71,7 @@ class InkHighlight extends InteractiveInkFeature {
|
||||
}
|
||||
|
||||
final BoxShape _shape;
|
||||
final double _radius;
|
||||
final BorderRadius _borderRadius;
|
||||
final ShapeBorder _customBorder;
|
||||
final RectCallback _rectCallback;
|
||||
@ -112,7 +115,7 @@ class InkHighlight extends InteractiveInkFeature {
|
||||
}
|
||||
switch (_shape) {
|
||||
case BoxShape.circle:
|
||||
canvas.drawCircle(rect.center, Material.defaultSplashRadius, paint);
|
||||
canvas.drawCircle(rect.center, _radius ?? Material.defaultSplashRadius, paint);
|
||||
break;
|
||||
case BoxShape.rectangle:
|
||||
if (_borderRadius != BorderRadius.zero) {
|
||||
|
||||
@ -840,6 +840,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
||||
referenceBox: referenceBox,
|
||||
color: getHighlightColorForType(type),
|
||||
shape: widget.highlightShape,
|
||||
radius: widget.radius,
|
||||
borderRadius: widget.borderRadius,
|
||||
customBorder: widget.customBorder,
|
||||
rectCallback: widget.getRectCallback(referenceBox),
|
||||
|
||||
@ -313,6 +313,36 @@ void main() {
|
||||
await gesture.up();
|
||||
});
|
||||
|
||||
testWidgets('ink response uses radius for focus highlight', (WidgetTester tester) async {
|
||||
FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
|
||||
final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
|
||||
await tester.pumpWidget(
|
||||
Material(
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
child: InkResponse(
|
||||
focusNode: focusNode,
|
||||
radius: 20,
|
||||
focusColor: const Color(0xff0000ff),
|
||||
onTap: () { },
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
|
||||
expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));
|
||||
focusNode.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
expect(inkFeatures, paints..circle(radius: 20, color: const Color(0xff0000ff)));
|
||||
});
|
||||
|
||||
testWidgets("ink response doesn't change color on focus when on touch device", (WidgetTester tester) async {
|
||||
FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
|
||||
final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user