in ThermionListenerWidget, don't return child before the input handler has initialized
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -85,38 +87,38 @@ class _ThermionListenerWidgetState extends State<ThermionListenerWidget> {
|
|||||||
|
|
||||||
Widget _desktop(double pixelRatio) {
|
Widget _desktop(double pixelRatio) {
|
||||||
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,
|
event.delta.toVector2() * pixelRatio);
|
||||||
event.delta.toVector2() * pixelRatio);
|
},
|
||||||
},
|
onPointerSignal: (PointerSignalEvent pointerSignal) {
|
||||||
onPointerSignal: (PointerSignalEvent pointerSignal) {
|
if (pointerSignal is PointerScrollEvent) {
|
||||||
if (pointerSignal is PointerScrollEvent) {
|
widget.inputHandler.onPointerScroll(
|
||||||
widget.inputHandler.onPointerScroll(
|
pointerSignal.localPosition.toVector2() * pixelRatio,
|
||||||
pointerSignal.localPosition.toVector2() * pixelRatio,
|
pointerSignal.scrollDelta.dy * pixelRatio);
|
||||||
pointerSignal.scrollDelta.dy * pixelRatio);
|
}
|
||||||
}
|
},
|
||||||
},
|
onPointerPanZoomStart: (pzs) {
|
||||||
onPointerPanZoomStart: (pzs) {
|
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.focusNode?.requestFocus();
|
widget.inputHandler.onPointerDown(
|
||||||
widget.inputHandler.onPointerDown(
|
d.localPosition.toVector2() * pixelRatio,
|
||||||
d.localPosition.toVector2() * pixelRatio,
|
d.buttons & kMiddleMouseButton != 0);
|
||||||
d.buttons & kMiddleMouseButton != 0);
|
},
|
||||||
},
|
onPointerMove: (PointerMoveEvent d) => widget.inputHandler
|
||||||
onPointerMove: (PointerMoveEvent d) => widget.inputHandler.onPointerMove(
|
.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,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _mobile(double pixelRatio) {
|
Widget _mobile(double pixelRatio) {
|
||||||
@@ -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))
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user