谷歌地图颤动手势在堆栈内不起作用

Bil*_*bbi 1 google-maps flutter

我正在使用 google_maps_flutter。我的小部件树是 Scaffold -> SingleChildScrollView -> Stack 然后是谷歌地图。我无法使用手势放大和缩小。

SingleChildScrollView( Stack(
            children: <Widget>[
              Container(
                height: MediaQuery.of(context).size.height - 10.0,
                width: MediaQuery.of(context).size.width * 1,
                child: _mapView
                    ? GoogleMap(
                        initialCameraPosition: CameraPosition(
                            target: _outletData[0].locationCoords, zoom: 12.0),
                        markers: Set.from(allMarkers),
                        onMapCreated: mapCreated,
                        zoomControlsEnabled: false,
                        zoomGesturesEnabled: true,
                        scrollGesturesEnabled: true,
                        compassEnabled: true,
                        rotateGesturesEnabled: true,
                        mapToolbarEnabled: true,
                        tiltGesturesEnabled: true,
                       
                      )
                    : Container(),
              ),
Run Code Online (Sandbox Code Playgroud)

我也尝试过下面的代码,但仍然无法使用两指触摸放大缩小

Stack(
            children: <Widget>[
              Container(
                height: MediaQuery.of(context).size.height - 10.0,
                width: MediaQuery.of(context).size.width * 1,
                child: _mapView
                    ? GoogleMap(
                        initialCameraPosition: CameraPosition(
                            target: _outletData[0].locationCoords, zoom: 12.0),
                        markers: Set.from(allMarkers),
                        onMapCreated: mapCreated,
                        zoomControlsEnabled: false,
                        zoomGesturesEnabled: true,
                        scrollGesturesEnabled: true,
                        compassEnabled: true,
                        rotateGesturesEnabled: true,
                        mapToolbarEnabled: true,
                        tiltGesturesEnabled: true,
                        gestureRecognizers: Set()
                          ..add(Factory<PanGestureRecognizer>(
                              () => PanGestureRecognizer()))
                          ..add(Factory<ScaleGestureRecognizer>(
                              () => ScaleGestureRecognizer()))
                          ..add(Factory<TapGestureRecognizer>(
                              () => TapGestureRecognizer()))
                          ..add(
                            Factory<VerticalDragGestureRecognizer>(
                                () => VerticalDragGestureRecognizer()),
                          ),
                      )
                    : Container(),
              ),
Run Code Online (Sandbox Code Playgroud)

小智 9

SingleChildScrollView仅支持用于滚动的垂直拖动。

添加gestureRecognizersEagerGestureRecognizerGoogleMap部件将允许派遣视图边界内的所有触摸事件。这包括用于放大和缩小地图的 2 指捏合手势。这将需要以下颤振包:

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
Run Code Online (Sandbox Code Playgroud)

在您的GoogleMap小部件中添加以下内容:

gestureRecognizers: < Factory < OneSequenceGestureRecognizer >> [
    new Factory < OneSequenceGestureRecognizer > (
        () => new EagerGestureRecognizer(),
    ),
].toSet()
Run Code Online (Sandbox Code Playgroud)

这是一个示例代码:

GoogleMap(
    initialCameraPosition:
    CameraPosition(target: LatLng(-34.397, 150.644)),
    onMapCreated: _onMapCreated,
    zoomControlsEnabled: false,
    zoomGesturesEnabled: true,
    scrollGesturesEnabled: true,
    compassEnabled: true,
    rotateGesturesEnabled: true,
    mapToolbarEnabled: true,
    tiltGesturesEnabled: true,
    gestureRecognizers: < Factory < OneSequenceGestureRecognizer >> [
        new Factory < OneSequenceGestureRecognizer > (
            () => new EagerGestureRecognizer(),
        ),
    ].toSet()
)
Run Code Online (Sandbox Code Playgroud)

我希望这有帮助!祝你的项目好运