From fe191ef9342fd054a2f59b5b0f70b89b25ad3592 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sun, 24 Aug 2025 14:46:10 +0800 Subject: [PATCH] opt dyn Signed-off-by: bggRGjQaUbCoE --- lib/common/widgets/dyn/ink_well.dart | 141 ++++++++++++++++++++++++--- 1 file changed, 127 insertions(+), 14 deletions(-) diff --git a/lib/common/widgets/dyn/ink_well.dart b/lib/common/widgets/dyn/ink_well.dart index 6723548e..14c197be 100644 --- a/lib/common/widgets/dyn/ink_well.dart +++ b/lib/common/widgets/dyn/ink_well.dart @@ -673,6 +673,12 @@ class _InkResponseState extends State<_InkResponseStateWidget> bool _hovering = false; final Map<_HighlightType, InkHighlight?> _highlights = <_HighlightType, InkHighlight?>{}; + late final Map> _actionMap = >{ + ActivateIntent: CallbackAction(onInvoke: activateOnIntent), + ButtonActivateIntent: CallbackAction( + onInvoke: activateOnIntent, + ), + }; WidgetStatesController? internalStatesController; bool get highlightsExist => _highlights.values @@ -1168,22 +1174,129 @@ class _InkResponseState extends State<_InkResponseStateWidget> updateHighlight(_HighlightType.hover, value: _hovering); } + bool get _canRequestFocus => + switch (MediaQuery.maybeNavigationModeOf(context)) { + NavigationMode.traditional || null => enabled && widget.canRequestFocus, + NavigationMode.directional => true, + }; + @override Widget build(BuildContext context) { - return GestureDetector( - onTapDown: _primaryEnabled ? handleTapDown : null, - onTapUp: _primaryEnabled ? handleTapUp : null, - onTap: _primaryEnabled ? handleTap : null, - onTapCancel: _primaryEnabled ? handleTapCancel : null, - onDoubleTap: widget.onDoubleTap != null ? handleDoubleTap : null, - onLongPress: widget.onLongPress != null ? handleLongPress : null, - onSecondaryTapDown: _secondaryEnabled ? handleSecondaryTapDown : null, - onSecondaryTapUp: _secondaryEnabled ? handleSecondaryTapUp : null, - onSecondaryTap: _secondaryEnabled ? handleSecondaryTap : null, - onSecondaryTapCancel: _secondaryEnabled ? handleSecondaryTapCancel : null, - behavior: HitTestBehavior.opaque, - excludeFromSemantics: true, - child: widget.child, + assert(widget.debugCheckContext(context)); + + final ThemeData theme = Theme.of(context); + const Set highlightableStates = { + WidgetState.focused, + WidgetState.hovered, + WidgetState.pressed, + }; + final Set nonHighlightableStates = statesController.value + .difference( + highlightableStates, + ); + // Each highlightable state will be resolved separately to get the corresponding color. + // For this resolution to be correct, the non-highlightable states should be preserved. + final Set pressed = { + ...nonHighlightableStates, + WidgetState.pressed, + }; + final Set focused = { + ...nonHighlightableStates, + WidgetState.focused, + }; + final Set hovered = { + ...nonHighlightableStates, + WidgetState.hovered, + }; + + Color getHighlightColorForType(_HighlightType type) { + return switch (type) { + // The pressed state triggers a ripple (ink splash), per the current + // Material Design spec. A separate highlight is no longer used. + // See https://material.io/design/interaction/states.html#pressed + _HighlightType.pressed => + widget.overlayColor?.resolve(pressed) ?? + widget.highlightColor ?? + theme.highlightColor, + _HighlightType.focus => + widget.overlayColor?.resolve(focused) ?? + widget.focusColor ?? + theme.focusColor, + _HighlightType.hover => + widget.overlayColor?.resolve(hovered) ?? + widget.hoverColor ?? + theme.hoverColor, + }; + } + + for (final _HighlightType type in _highlights.keys) { + _highlights[type]?.color = getHighlightColorForType(type); + } + + _currentSplash?.color = + widget.overlayColor?.resolve(statesController.value) ?? + widget.splashColor ?? + Theme.of(context).splashColor; + + final MouseCursor effectiveMouseCursor = + WidgetStateProperty.resolveAs( + widget.mouseCursor ?? WidgetStateMouseCursor.clickable, + statesController.value, + ); + + return _ParentInkResponseProvider( + state: this, + child: Actions( + actions: _actionMap, + child: Focus( + focusNode: widget.focusNode, + canRequestFocus: _canRequestFocus, + onFocusChange: handleFocusUpdate, + autofocus: widget.autofocus, + child: MouseRegion( + cursor: effectiveMouseCursor, + onEnter: handleMouseEnter, + onExit: handleMouseExit, + child: DefaultSelectionStyle.merge( + mouseCursor: effectiveMouseCursor, + child: Semantics( + onTap: widget.excludeFromSemantics || widget.onTap == null + ? null + : simulateTap, + onLongPress: + widget.excludeFromSemantics || widget.onLongPress == null + ? null + : simulateLongPress, + child: GestureDetector( + onTapDown: _primaryEnabled ? handleTapDown : null, + onTapUp: _primaryEnabled ? handleTapUp : null, + onTap: _primaryEnabled ? handleTap : null, + onTapCancel: _primaryEnabled ? handleTapCancel : null, + onDoubleTap: widget.onDoubleTap != null + ? handleDoubleTap + : null, + onLongPress: widget.onLongPress != null + ? handleLongPress + : null, + onSecondaryTapDown: _secondaryEnabled + ? handleSecondaryTapDown + : null, + onSecondaryTapUp: _secondaryEnabled + ? handleSecondaryTapUp + : null, + onSecondaryTap: _secondaryEnabled ? handleSecondaryTap : null, + onSecondaryTapCancel: _secondaryEnabled + ? handleSecondaryTapCancel + : null, + behavior: HitTestBehavior.opaque, + excludeFromSemantics: true, + child: widget.child, + ), + ), + ), + ), + ), + ), ); } }