From cb8562e163f155622fc3d7d76b3d4758fb4bd965 Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Wed, 10 Jun 2020 12:25:04 -0700 Subject: [PATCH] Make the InkResponse's focus highlight honor the radius parameter (#59117) --- .../lib/src/material/ink_highlight.dart | 5 +++- .../flutter/lib/src/material/ink_well.dart | 1 + .../flutter/test/material/ink_well_test.dart | 30 +++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/ink_highlight.dart b/packages/flutter/lib/src/material/ink_highlight.dart index 46355c30f7e..4775c4f9bb2 100644 --- a/packages/flutter/lib/src/material/ink_highlight.dart +++ b/packages/flutter/lib/src/material/ink_highlight.dart @@ -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) { diff --git a/packages/flutter/lib/src/material/ink_well.dart b/packages/flutter/lib/src/material/ink_well.dart index aabc14c5826..db5e8b6f491 100644 --- a/packages/flutter/lib/src/material/ink_well.dart +++ b/packages/flutter/lib/src/material/ink_well.dart @@ -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), diff --git a/packages/flutter/test/material/ink_well_test.dart b/packages/flutter/test/material/ink_well_test.dart index 5385c605ae8..43ba477ab5b 100644 --- a/packages/flutter/test/material/ink_well_test.dart +++ b/packages/flutter/test/material/ink_well_test.dart @@ -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');