首页 > 解决方案 > Flutter - 地图中不断闪烁

问题描述

我有以下问题:我正在使用Location包实时获取位置,我已经在地图中设置了标记,当位置更新时,地图开始闪烁:https://photos.app。 goo.gl/GsFdB4pHzjoUcVZ6A

更新标记位置的代码是:

subscription = location.onLocationChanged.listen((currentLocation) {
  //Update the animated marker
      setState(() {
        Marker sourceMarker = Marker(
          markerId: sourceId,
          position: LatLng(
            currentLocation.latitude,
            currentLocation.longitude,
          ),
        );
        _markers[sourceId] = sourceMarker;
   });
});

标签: fluttergoogle-maps

解决方案


我面临着类似的事情,我能够解决它。

不确定这是否会有所帮助,但仍然试一试。

我的代码结构是这样的:

  • 我的地图在一个单独的类中 ( ShowMap)
  • 我在屏幕上使用了ShowMap课程HomeStack

这就是整个问题。

基本上,ShowMap有自己的build方法的类导致了闪烁。所以,我不得不转换ShowMap成一个function返回的小部件。

由于ShowMap没有自己的,build它正在使用屏幕,因此闪烁停止。buildHome


推荐阅读