mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
Verifying if GestureBinding is ready and if not, throwing a meaningful error
This commit is contained in:
@ -35,3 +35,4 @@ Here are some example of more complex Gesture Recognizers:
|
|||||||
..onTapUp = (TapUpDetails details) => this.handleTap(details.globalPosition);;
|
..onTapUp = (TapUpDetails details) => this.handleTap(details.globalPosition);;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
__ATTENTION:__ `Flame.util.addGestureRecognizer` must be called after the `runApp`, otherwise Flutter's `GestureBinding` will not be initialized yet and exceptions will occur.
|
||||||
|
|||||||
@ -56,6 +56,10 @@ class Util {
|
|||||||
///
|
///
|
||||||
/// Use this in order to get it to work in case your app also contains other widgets.
|
/// Use this in order to get it to work in case your app also contains other widgets.
|
||||||
void addGestureRecognizer(GestureRecognizer recognizer) {
|
void addGestureRecognizer(GestureRecognizer recognizer) {
|
||||||
|
if (GestureBinding.instance == null) {
|
||||||
|
throw new Exception("GestureBinding is not initialized yet, this probably happened because addGestureRecognizer was called before the runApp method");
|
||||||
|
}
|
||||||
|
|
||||||
GestureBinding.instance.pointerRouter.addGlobalRoute((PointerEvent e) {
|
GestureBinding.instance.pointerRouter.addGlobalRoute((PointerEvent e) {
|
||||||
if (e is PointerDownEvent) {
|
if (e is PointerDownEvent) {
|
||||||
recognizer.addPointer(e);
|
recognizer.addPointer(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user