mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-11-01 01:18:38 +08:00 
			
		
		
		
	Verifying if GestureBinding is ready and if not, throwing a meaningful error
This commit is contained in:
		| @ -34,4 +34,5 @@ Here are some example of more complex Gesture Recognizers: | |||||||
|         return new TapGestureRecognizer() |         return new TapGestureRecognizer() | ||||||
|             ..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
	 Erick Zanardo
					Erick Zanardo