3

I want to create a Google Map widget which will not handle any clicks, gestures - just a static map. I understand I need somehow to set gestureRecognizers but can't figure out which class will lock all the gestures. What should I use instead of ScaleGestureRecognizer() ?

Setting gestureRecognizersto null doesn't help.

When this set is empty or null, the map will only handle pointer events for gestures that were not claimed by any other gesture recognizer.

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class StaticMap extends StatelessWidget {
  final CameraPosition cameraPosition;
  StaticMap(this.cameraPosition);

  @override
  Widget build(BuildContext context) {
    return GoogleMap(
      mapType: MapType.normal,
      initialCameraPosition: cameraPosition,
      gestureRecognizers: {
        Factory<OneSequenceGestureRecognizer>(() => ScaleGestureRecognizer()),
      },
    );
  }
}
vovahost
  • 34,185
  • 17
  • 113
  • 116
  • Did my solution worked for you? – Mangaldeep Pannu Jun 12 '19 at 06:59
  • @MangaldeepPannu Yes, your solution works, I just ended up using `IgnorePointer(ignoring: false, ...)`. Was waiting a bit to see if maybe someone would suggest a way to disable the map actions by setting a custom `gestureRecognizers`. – vovahost Jun 12 '19 at 09:27

1 Answers1

8

Try using AbsorbPointer

Make GoogleMap child of AbsorbPointer and set its absorbing property to true

return AbsorbPointer(
  absorbing: true,
  child: GoogleMap(
    mapType: MapType.normal,
    initialCameraPosition: cameraPosition,
    gestureRecognizers: {
    Factory<OneSequenceGestureRecognizer>(() => ScaleGestureRecognizer()),
    }
  )
);

You can also set it's absorbing property false when you want to detect events

For more info on AbsorbPointer refer here

Mangaldeep Pannu
  • 3,738
  • 2
  • 26
  • 45