I'm using google_maps_flutter and wish to perform an action when the user performs a gesture on the map, whether it be zoom/tilt/move/rotate. However I'm unable to use the onCameraMoveStarted property in GoogleMap class as it also recognizes non-gesture user action caused as well as programmed animations (which my app utilizes), with no way (as far as I know, please correct me otherwise), to differentiate between them.
Thus I thought of using the flutter widget GestureDetector, wrapping the map inside it so that I would be able to change variables based on the gestures detected by GestureDetector to cause changes indirectly in the map.
No problems initially, it acts as a transparent layer and the map can be moved/tilted/rotated/zoomed normally. However, upon adding a function to execute through onPanStart, onPanUpdate, or onPanEnd all make the map unable to be interacted with through gestures. I suppose it is all being captured by the GestureDetector, but is there no way I can do said extra task asynchronously while passing the gesture along to the child anyway?
Here's the structure, btw:
build(context) {
return Scaffold(
body: GestureDetector(
behavior: HitTestBehavior.deferToChild,
onPanStart: {...}
child:
GoogleMap(...),
),
...
);
}
Thanks in advance, any help much appreciated.
I've found a solution, which might work for you.
class Test extends DragGestureRecognizer {
Function _test;
Test(this._test);
@override
void resolve(GestureDisposition disposition) {
super.resolve(disposition);
this._test();
}
}
...
return GoogleMap(
...
gestureRecognizers: Set()
..add(Factory<DragGestureRecognizer>(() => Test(() {
if (_focusEnabled) {
setState(() {
_focusEnabled = false;
});
}
})),
);
This runs your function on every interaction with the map. But i did'nt find a way to differentiate between the events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With