本文介绍了静态Google地图(禁用所有手势)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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() ?

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

推荐答案

尝试使用 AbsorbPointer

使 AbsorbPointer GoogleMap child 并将其吸收属性设置为 true

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

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

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

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

For more info on AbsorbPointer refer here

这篇关于静态Google地图(禁用所有手势)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:44