为什么 Flutter 中的 Google 地图上出现双折线而不是一条?

问题描述 投票:0回答:1

在我的 Flutter 项目中,我一直在更新卡片的同时绘制折线。总体来说,实施已经成功,并且折线按预期出现。但是,我遇到了一个问题,有时会显示多条折线而不是仅显示一条。这种意外的行为令人费解,我正在寻找一种解决方案来确保仅一致地显示一条折线。任何有关解决此问题的指导或见解将不胜感激。

这是我的代码:

class MapViewProvider extends ChangeNotifier {
    Set<Polyline> polyline = {};
    
    void drawPolyline(LatLng selectedPoint) async {
    //get origin lat long
    LatLng? currentPoint = chooseWhereFromDrawPolyline();
    if (currentPoint == null) return;

    //get polyline lat long
    List<LatLng>? latLong = await MyPolyline().getPolylinePoints(
      currentPoint,
      selectedPoint,
    );
    if (latLong == null) return;

    //clear polyline
    polyline = {};
    notifyListeners();

    //save to polyline
    polyline = {
      Polyline(
        polylineId: PolylineId(polylineId),
        visible: true,
        points: latLong,
        geodesic: false,
        color: ColorsRes.dark500.withOpacity(.6),
        width: 5,
        startCap: Cap.roundCap,
        endCap: Cap.roundCap,
      ),
    };
    notifyListeners();
  }
}
GoogleMap(
              initialCameraPosition: _provider.initialMapPosition(),
              mapType: MapType.normal,
              onMapCreated: _provider.onMapCreated,
              onCameraMove: _provider.onCameraMove,
              onCameraIdle: _provider.onCameraIdle,
              onTap: _provider.onTap,
              markers: _provider.markers,
              polylines: _provider.polyline.isEmpty
                  ? {}
                  : <Polyline>{_provider.polyline.last},

              zoomControlsEnabled: false,
              myLocationEnabled: true,
              myLocationButtonEnabled: false,
            )
flutter polyline google-polyline fluttermap
1个回答
0
投票

您能否分享您项目的整个代码库或 git 存储库。我想在我的应用程序中实现多段线的此功能,但无法这样做。

© www.soinside.com 2019 - 2024. All rights reserved.