Unverified Commit 5bb8d8fc authored by Tong Mu's avatar Tong Mu Committed by GitHub

Split Mouse from Listener (#36217)

- Splits on{Enter,Hover,Exit} from Listener to MouseRegion. Deprecated API is kept for compatibility.
- Splits on{Enter,Hover,Exit} from RenderPointerListener to RenderMouseRegion.
parent ced20783
<<skip until matching line>> <<skip until matching line>>
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building The following assertion was thrown building Listener
RawGestureDetector-\[LabeledGlobalKey<RawGestureDetectorState>#.+\]\(state:
RawGestureDetectorState#.+\(gestures: <none>, behavior: opaque\)\):
'package:flutter\/src\/painting\/basic_types\.dart': Failed assertion: line 223 pos 10: 'textDirection 'package:flutter\/src\/painting\/basic_types\.dart': Failed assertion: line 223 pos 10: 'textDirection
!= null': is not true\. != null': is not true\.
......
<<skip until matching line>> <<skip until matching line>>
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building The following assertion was thrown building Listener
RawGestureDetector-\[LabeledGlobalKey<RawGestureDetectorState>#.+\]\(state:
RawGestureDetectorState#.+\(gestures: <none>, behavior: opaque\)\):
'package:flutter\/src\/painting\/basic_types\.dart': Failed assertion: line 223 pos 10: 'textDirection 'package:flutter\/src\/painting\/basic_types\.dart': Failed assertion: line 223 pos 10: 'textDirection
!= null': is not true\. != null': is not true\.
......
...@@ -685,8 +685,8 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe ...@@ -685,8 +685,8 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
bool get enabled => _isWidgetEnabled(widget); bool get enabled => _isWidgetEnabled(widget);
void _handlePointerEnter(PointerEnterEvent event) => _handleHoverChange(true); void _handleMouseEnter(PointerEnterEvent event) => _handleHoverChange(true);
void _handlePointerExit(PointerExitEvent event) => _handleHoverChange(false); void _handleMouseExit(PointerExitEvent event) => _handleHoverChange(false);
void _handleHoverChange(bool hovering) { void _handleHoverChange(bool hovering) {
if (_hovering != hovering) { if (_hovering != hovering) {
_hovering = hovering; _hovering = hovering;
...@@ -702,10 +702,9 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe ...@@ -702,10 +702,9 @@ class _InkResponseState<T extends InkResponse> extends State<T> with AutomaticKe
_highlights[type]?.color = getHighlightColorForType(type); _highlights[type]?.color = getHighlightColorForType(type);
} }
_currentSplash?.color = widget.splashColor ?? Theme.of(context).splashColor; _currentSplash?.color = widget.splashColor ?? Theme.of(context).splashColor;
return Listener( return MouseRegion(
onPointerEnter: enabled ? _handlePointerEnter : null, onEnter: enabled ? _handleMouseEnter : null,
onPointerExit: enabled ? _handlePointerExit : null, onExit: enabled ? _handleMouseExit : null,
behavior: HitTestBehavior.translucent,
child: GestureDetector( child: GestureDetector(
onTapDown: enabled ? _handleTapDown : null, onTapDown: enabled ? _handleTapDown : null,
onTap: enabled ? () => _handleTap(context) : null, onTap: enabled ? () => _handleTap(context) : null,
......
...@@ -887,8 +887,8 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -887,8 +887,8 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
super.deactivate(); super.deactivate();
} }
void _handlePointerEnter(PointerEnterEvent event) => _handleHover(true); void _handleMouseEnter(PointerEnterEvent event) => _handleHover(true);
void _handlePointerExit(PointerExitEvent event) => _handleHover(false); void _handleMouseExit(PointerExitEvent event) => _handleHover(false);
void _handleHover(bool hovering) { void _handleHover(bool hovering) {
if (hovering != _isHovering) { if (hovering != _isHovering) {
...@@ -1020,9 +1020,9 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -1020,9 +1020,9 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
_effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length); _effectiveController.selection = TextSelection.collapsed(offset: _effectiveController.text.length);
_requestKeyboard(); _requestKeyboard();
}, },
child: Listener( child: MouseRegion(
onPointerEnter: _handlePointerEnter, onEnter: _handleMouseEnter,
onPointerExit: _handlePointerExit, onExit: _handleMouseExit,
child: IgnorePointer( child: IgnorePointer(
ignoring: !(widget.enabled ?? widget.decoration?.enabled ?? true), ignoring: !(widget.enabled ?? widget.decoration?.enabled ?? true),
child: _selectionGestureDetectorBuilder.buildGestureDetector( child: _selectionGestureDetectorBuilder.buildGestureDetector(
......
...@@ -399,9 +399,9 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin { ...@@ -399,9 +399,9 @@ class _TooltipState extends State<Tooltip> with SingleTickerProviderStateMixin {
// Only check for hovering if there is a mouse connected. // Only check for hovering if there is a mouse connected.
if (_mouseIsConnected) { if (_mouseIsConnected) {
result = Listener( result = MouseRegion(
onPointerEnter: (PointerEnterEvent event) => _showTooltip(), onEnter: (PointerEnterEvent event) => _showTooltip(),
onPointerExit: (PointerExitEvent event) => _hideTooltip(), onExit: (PointerExitEvent event) => _hideTooltip(),
child: result, child: result,
); );
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment