feat: add FocusNode to ThermionListenerWidget

This commit is contained in:
Nick Fisher
2024-12-23 14:31:04 +08:00
parent 024643e3a1
commit 5e89dc43e8

View File

@@ -26,6 +26,8 @@ class ThermionListenerWidget extends StatefulWidget {
/// ///
final Widget? child; final Widget? child;
final FocusNode? focusNode;
/// ///
/// The handler to use for interpreting gestures/pointer movements. /// The handler to use for interpreting gestures/pointer movements.
/// ///
@@ -34,6 +36,7 @@ class ThermionListenerWidget extends StatefulWidget {
const ThermionListenerWidget({ const ThermionListenerWidget({
Key? key, Key? key,
required this.inputHandler, required this.inputHandler,
this.focusNode,
this.child, this.child,
}) : super(key: key); }) : super(key: key);
@@ -81,7 +84,10 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
} }
Widget _desktop(double pixelRatio) { Widget _desktop(double pixelRatio) {
return Listener( return Focus(
focusNode: widget.focusNode,
child:Listener(
onPointerHover: (event) { onPointerHover: (event) {
widget.inputHandler.onPointerHover( widget.inputHandler.onPointerHover(
event.localPosition.toVector2() * pixelRatio, event.localPosition.toVector2() * pixelRatio,
@@ -98,6 +104,7 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
throw Exception("TODO - is this a pinch zoom on laptop trackpad?"); throw Exception("TODO - is this a pinch zoom on laptop trackpad?");
}, },
onPointerDown: (d) { onPointerDown: (d) {
widget.focusNode?.requestFocus();
widget.inputHandler.onPointerDown( widget.inputHandler.onPointerDown(
d.localPosition.toVector2() * pixelRatio, d.localPosition.toVector2() * pixelRatio,
d.buttons & kMiddleMouseButton != 0); d.buttons & kMiddleMouseButton != 0);
@@ -109,7 +116,7 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
onPointerUp: (d) => onPointerUp: (d) =>
widget.inputHandler.onPointerUp(d.buttons & kMiddleMouseButton != 0), widget.inputHandler.onPointerUp(d.buttons & kMiddleMouseButton != 0),
child: widget.child, child: widget.child,
); ));
} }
Widget _mobile(double pixelRatio) { Widget _mobile(double pixelRatio) {