in ThermionListenerWidget, don't return child before the input handler has initialized

This commit is contained in:
Nick Fisher
2025-03-28 11:46:11 +08:00
parent 548dccf776
commit b69977929c

View File

@@ -15,8 +15,7 @@ extension OffsetExtension on Offset {
} }
/// ///
/// A widget that captures swipe/pointer events. /// Captures swipe/pointer events and forwards to the provided [InputHandler].
/// This is a dumb listener; events are forwarded to a [InputHandler].
/// ///
class ThermionListenerWidget extends StatefulWidget { class ThermionListenerWidget extends StatefulWidget {
/// ///
@@ -26,6 +25,9 @@ class ThermionListenerWidget extends StatefulWidget {
/// ///
final Widget? child; final Widget? child;
///
///
///
final FocusNode? focusNode; final FocusNode? focusNode;
/// ///
@@ -87,7 +89,6 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
return Focus( return Focus(
focusNode: widget.focusNode, focusNode: widget.focusNode,
child: Listener( child: Listener(
onPointerHover: (event) { onPointerHover: (event) {
widget.inputHandler.onPointerHover( widget.inputHandler.onPointerHover(
event.localPosition.toVector2() * pixelRatio, event.localPosition.toVector2() * pixelRatio,
@@ -109,12 +110,13 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
d.localPosition.toVector2() * pixelRatio, d.localPosition.toVector2() * pixelRatio,
d.buttons & kMiddleMouseButton != 0); d.buttons & kMiddleMouseButton != 0);
}, },
onPointerMove: (PointerMoveEvent d) => widget.inputHandler.onPointerMove( onPointerMove: (PointerMoveEvent d) => widget.inputHandler
.onPointerMove(
d.localPosition.toVector2() * pixelRatio, d.localPosition.toVector2() * pixelRatio,
d.delta.toVector2() * pixelRatio, d.delta.toVector2() * pixelRatio,
d.buttons & kMiddleMouseButton != 0), d.buttons & kMiddleMouseButton != 0),
onPointerUp: (d) => onPointerUp: (d) => widget.inputHandler
widget.inputHandler.onPointerUp(d.buttons & kMiddleMouseButton != 0), .onPointerUp(d.buttons & kMiddleMouseButton != 0),
child: widget.child, child: widget.child,
)); ));
} }
@@ -134,12 +136,10 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
future: widget.inputHandler.initialized, future: widget.inputHandler.initialized,
builder: (_, initialized) { builder: (_, initialized) {
if (initialized.data != true) { if (initialized.data != true) {
return widget.child ?? Container(); return Container();
} }
return Stack(children: [ return SizedBox.expand(
if (isDesktop) Positioned.fill(child: _desktop(pixelRatio)), child: isDesktop ? _desktop(pixelRatio) : _mobile(pixelRatio));
if (!isDesktop) Positioned.fill(child: _mobile(pixelRatio))
]);
}); });
}); });
} }