Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static Google map (disable all gestures)

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()),
      },
    );
  }
}
like image 701
vovahost Avatar asked Oct 17 '25 22:10

vovahost


1 Answers

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

like image 127
Mangaldeep Pannu Avatar answered Oct 20 '25 11:10

Mangaldeep Pannu