Unverified Commit 0d221dc2 authored by chunhtai's avatar chunhtai Committed by GitHub

Clean up mouse region code (#96636)

* Clean up mouse region code

* remove even more code
parent f12c83ea
...@@ -6185,7 +6185,7 @@ class Listener extends SingleChildRenderObjectWidget { ...@@ -6185,7 +6185,7 @@ class Listener extends SingleChildRenderObjectWidget {
/// ///
/// * [Listener], a similar widget that tracks pointer events when the pointer /// * [Listener], a similar widget that tracks pointer events when the pointer
/// has buttons pressed. /// has buttons pressed.
class MouseRegion extends StatefulWidget { class MouseRegion extends SingleChildRenderObjectWidget {
/// Creates a widget that forwards mouse events to callbacks. /// Creates a widget that forwards mouse events to callbacks.
/// ///
/// By default, all callbacks are empty, [cursor] is [MouseCursor.defer], and /// By default, all callbacks are empty, [cursor] is [MouseCursor.defer], and
...@@ -6197,10 +6197,10 @@ class MouseRegion extends StatefulWidget { ...@@ -6197,10 +6197,10 @@ class MouseRegion extends StatefulWidget {
this.onHover, this.onHover,
this.cursor = MouseCursor.defer, this.cursor = MouseCursor.defer,
this.opaque = true, this.opaque = true,
this.child, Widget? child,
}) : assert(cursor != null), }) : assert(cursor != null),
assert(opaque != null), assert(opaque != null),
super(key: key); super(key: key, child: child);
/// Triggered when a mouse pointer has entered this widget. /// Triggered when a mouse pointer has entered this widget.
/// ///
...@@ -6347,13 +6347,26 @@ class MouseRegion extends StatefulWidget { ...@@ -6347,13 +6347,26 @@ class MouseRegion extends StatefulWidget {
/// This defaults to true. /// This defaults to true.
final bool opaque; final bool opaque;
/// The widget below this widget in the tree. @override
/// RenderMouseRegion createRenderObject(BuildContext context) {
/// {@macro flutter.widgets.ProxyWidget.child} return RenderMouseRegion(
final Widget? child; onEnter: onEnter,
onHover: onHover,
onExit: onExit,
cursor: cursor,
opaque: opaque,
);
}
@override @override
State<MouseRegion> createState() => _MouseRegionState(); void updateRenderObject(BuildContext context, RenderMouseRegion renderObject) {
renderObject
..onEnter = onEnter
..onHover = onHover
..onExit = onExit
..cursor = cursor
..opaque = opaque;
}
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
...@@ -6371,51 +6384,6 @@ class MouseRegion extends StatefulWidget { ...@@ -6371,51 +6384,6 @@ class MouseRegion extends StatefulWidget {
} }
} }
class _MouseRegionState extends State<MouseRegion> {
void handleExit(PointerExitEvent event) {
if (widget.onExit != null && mounted)
widget.onExit!(event);
}
PointerExitEventListener? getHandleExit() {
return widget.onExit == null ? null : handleExit;
}
@override
Widget build(BuildContext context) {
return _RawMouseRegion(this);
}
}
class _RawMouseRegion extends SingleChildRenderObjectWidget {
_RawMouseRegion(this.owner) : super(child: owner.widget.child);
final _MouseRegionState owner;
@override
RenderMouseRegion createRenderObject(BuildContext context) {
final MouseRegion widget = owner.widget;
return RenderMouseRegion(
onEnter: widget.onEnter,
onHover: widget.onHover,
onExit: owner.getHandleExit(),
cursor: widget.cursor,
opaque: widget.opaque,
);
}
@override
void updateRenderObject(BuildContext context, RenderMouseRegion renderObject) {
final MouseRegion widget = owner.widget;
renderObject
..onEnter = widget.onEnter
..onHover = widget.onHover
..onExit = owner.getHandleExit()
..cursor = widget.cursor
..opaque = widget.opaque;
}
}
/// A widget that creates a separate display list for its child. /// A widget that creates a separate display list for its child.
/// ///
/// This widget creates a separate display list for its child, which /// This widget creates a separate display list for its child, which
......
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