flutter - 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;
});
});
解决方案
我面临着类似的事情,我能够解决它。
不确定这是否会有所帮助,但仍然试一试。
我的代码结构是这样的:
- 我的地图在一个单独的类中 (
ShowMap
) - 我在屏幕上使用了
ShowMap
课程Home
Stack
这就是整个问题。
基本上,ShowMap
有自己的build
方法的类导致了闪烁。所以,我不得不转换ShowMap
成一个function
返回的小部件。
由于ShowMap
没有自己的,build
它正在使用屏幕,因此闪烁停止。build
Home
推荐阅读
- java - Spark 中的复制是如何工作的?
- python - Django:自定义 LoginView 未对用户进行身份验证
- wordpress - 在 Wordpress 中创建重定向规则
- python - 如何向现有 JSON 文件添加嵌套未知数量级别的新 JSON 节点?
- visual-studio-code - 在编辑器中折叠部分时是否可以折叠降价预览?
- objective-c - 如何在 Swift 代码中使用 Facebook Places SDK
- node.js - Squeelize 无法访问外键
- java - RecyclerView 项目的属性在使用 DataBinding 时自动更改
- google-sheets - 根据表的内容在第 1 行查找结果
- python - PyMongo 对列表中的项目进行全文搜索