10

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.

Terrornado
  • 793
  • 3
  • 9
  • 21

2 Answers2

5

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.

Johanno
  • 66
  • 4
-1

This may help some, saw this somewhere and forgot about it. Wrap the map in a listener:

Listener(
        onPointerDown: (e) {
          print("USER IS DRAGGING");
          print(e);
        },
Wesley Barnes
  • 554
  • 4
  • 18