Hide InkWell hover highlight when an hovered InkWell is disabled (#118026)
This commit is contained in:
parent
466cb54633
commit
ad7322ddbf
@ -842,14 +842,14 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
|||||||
widget.radius != oldWidget.radius ||
|
widget.radius != oldWidget.radius ||
|
||||||
widget.borderRadius != oldWidget.borderRadius ||
|
widget.borderRadius != oldWidget.borderRadius ||
|
||||||
widget.highlightShape != oldWidget.highlightShape) {
|
widget.highlightShape != oldWidget.highlightShape) {
|
||||||
final InkHighlight? hoverHighLight = _highlights[_HighlightType.hover];
|
final InkHighlight? hoverHighlight = _highlights[_HighlightType.hover];
|
||||||
if (hoverHighLight != null) {
|
if (hoverHighlight != null) {
|
||||||
hoverHighLight.dispose();
|
hoverHighlight.dispose();
|
||||||
updateHighlight(_HighlightType.hover, value: _hovering, callOnHover: false);
|
updateHighlight(_HighlightType.hover, value: _hovering, callOnHover: false);
|
||||||
}
|
}
|
||||||
final InkHighlight? focusHighLight = _highlights[_HighlightType.focus];
|
final InkHighlight? focusHighlight = _highlights[_HighlightType.focus];
|
||||||
if (focusHighLight != null) {
|
if (focusHighlight != null) {
|
||||||
focusHighLight.dispose();
|
focusHighlight.dispose();
|
||||||
// Do not call updateFocusHighlights() here because it is called below
|
// Do not call updateFocusHighlights() here because it is called below
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -857,6 +857,13 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
|||||||
statesController.update(MaterialState.disabled, !enabled);
|
statesController.update(MaterialState.disabled, !enabled);
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
statesController.update(MaterialState.pressed, false);
|
statesController.update(MaterialState.pressed, false);
|
||||||
|
// Remove the existing hover highlight immediately when enabled is false.
|
||||||
|
// Do not rely on updateHighlight or InkHighlight.deactivate to not break
|
||||||
|
// the expected lifecycle which is updating _hovering when the mouse exit.
|
||||||
|
// Manually updating _hovering here or calling InkHighlight.deactivate
|
||||||
|
// will lead to onHover not being called or call when it is not allowed.
|
||||||
|
final InkHighlight? hoverHighlight = _highlights[_HighlightType.hover];
|
||||||
|
hoverHighlight?.dispose();
|
||||||
}
|
}
|
||||||
// Don't call widget.onHover because many widgets, including the button
|
// Don't call widget.onHover because many widgets, including the button
|
||||||
// widgets, apply setState to an ancestor context from onHover.
|
// widgets, apply setState to an ancestor context from onHover.
|
||||||
@ -937,7 +944,7 @@ class _InkResponseState extends State<_InkResponseStateWidget>
|
|||||||
_highlights[type] = InkHighlight(
|
_highlights[type] = InkHighlight(
|
||||||
controller: Material.of(context),
|
controller: Material.of(context),
|
||||||
referenceBox: referenceBox,
|
referenceBox: referenceBox,
|
||||||
color: resolvedOverlayColor,
|
color: enabled ? resolvedOverlayColor : resolvedOverlayColor.withAlpha(0),
|
||||||
shape: widget.highlightShape,
|
shape: widget.highlightShape,
|
||||||
radius: widget.radius,
|
radius: widget.radius,
|
||||||
borderRadius: widget.borderRadius,
|
borderRadius: widget.borderRadius,
|
||||||
|
@ -1722,6 +1722,56 @@ testWidgets('InkResponse radius can be updated', (WidgetTester tester) async {
|
|||||||
expect(hover, false);
|
expect(hover, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('hovered ink well draws a transparent highlight when disabled', (WidgetTester tester) async {
|
||||||
|
Widget buildFrame({ required bool enabled }) {
|
||||||
|
return Material(
|
||||||
|
child: Directionality(
|
||||||
|
textDirection: TextDirection.ltr,
|
||||||
|
child: Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: enabled ? () { } : null,
|
||||||
|
onHover: (bool value) { },
|
||||||
|
hoverColor: const Color(0xff00ff00),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await tester.pumpWidget(buildFrame(enabled: true));
|
||||||
|
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||||
|
await gesture.addPointer();
|
||||||
|
|
||||||
|
// Hover the enabled InkWell.
|
||||||
|
await gesture.moveTo(tester.getCenter(find.byType(InkWell)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
find.byType(Material),
|
||||||
|
paints
|
||||||
|
..rect(
|
||||||
|
color: const Color(0xff00ff00),
|
||||||
|
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Disable the hovered InkWell.
|
||||||
|
await tester.pumpWidget(buildFrame(enabled: false));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
find.byType(Material),
|
||||||
|
paints
|
||||||
|
..rect(
|
||||||
|
color: const Color(0x0000ff00),
|
||||||
|
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
testWidgets('Changing InkWell.enabled should not trigger TextButton setState()', (WidgetTester tester) async {
|
testWidgets('Changing InkWell.enabled should not trigger TextButton setState()', (WidgetTester tester) async {
|
||||||
Widget buildFrame({ required bool enabled }) {
|
Widget buildFrame({ required bool enabled }) {
|
||||||
return Material(
|
return Material(
|
||||||
|
@ -979,7 +979,7 @@ void main() {
|
|||||||
paints
|
paints
|
||||||
..rect()
|
..rect()
|
||||||
..rect(
|
..rect(
|
||||||
color: Colors.orange[500],
|
color: Colors.orange[500]!.withAlpha(0),
|
||||||
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
|
rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
|
||||||
)
|
)
|
||||||
..rect(
|
..rect(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user