静态Google地图(禁用所有手势)

时间:2019-06-11 04:17:01

标签: flutter flutter-layout flutter-plugin

我想创建一个Google Map小部件,该小部件将不会处理任何点击和手势-只会处理静态地图。 我知道我需要某种方式设置gestureRecognizers,但无法弄清楚哪个类会锁定所有手势。我应该用什么代替ScaleGestureRecognizer()

gestureRecognizers设置为无济于事。

  

如果此集合为空或为null,则地图将仅处理其他手势识别器未声明的手势的指针事件。

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()),
      },
    );
  }
}

1 个答案:

答案 0 :(得分:1)

尝试使用 AbsorbPointer

制作GoogleMap中的child AbsorbPointer并将其absorbing属性设置为true

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

当您要检测事件时,还可以将其设置为absorbing属性false

有关AbsorbPointer的更多信息,请参考here