From a80218d1ed3c73163588ab9c98fee7cb6ab89ea5 Mon Sep 17 00:00:00 2001 From: Erick Zanardo Date: Fri, 1 Feb 2019 12:53:32 -0200 Subject: [PATCH] Verifying if GestureBinding is ready and if not, throwing a meaningful error --- doc/input.md | 3 ++- lib/util.dart | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/input.md b/doc/input.md index 31919554a..48be662d6 100644 --- a/doc/input.md +++ b/doc/input.md @@ -34,4 +34,5 @@ Here are some example of more complex Gesture Recognizers: return new TapGestureRecognizer() ..onTapUp = (TapUpDetails details) => this.handleTap(details.globalPosition);; } -``` \ No newline at end of file +``` +__ATTENTION:__ `Flame.util.addGestureRecognizer` must be called after the `runApp`, otherwise Flutter's `GestureBinding` will not be initialized yet and exceptions will occur. diff --git a/lib/util.dart b/lib/util.dart index 2daab8218..7c85c5da7 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -56,6 +56,10 @@ class Util { /// /// Use this in order to get it to work in case your app also contains other widgets. 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) { if (e is PointerDownEvent) { recognizer.addPointer(e);