【发布时间】:2021-09-11 19:13:25
【问题描述】:
如何在加载数据或等待数据加载时重新加载消费者。我正在使用 Future Provider,并且在加载数据(currentPosition Fetched)并在等待时使用circularProgress() 时,一切都在重建自身。但是消费者并没有重建自己,也不能将等待与消费者包一起使用。当我在调试时保存代码时,它热重载一切都很好,但这不是一个解决方案。我希望消费者在获取数据时自动重新加载。我正在获取数据以在 google_Maps_Flutter 上制作标记
body: (currentPosition != null)
? Consumer<List<Bar>>(builder: (_, places, child) {
List.generate(places.length, (index) async {
print(places.length);
print(index);
print(imageUrl(places[index].photoRef));
List<String> wordList = places[index].name.split(" ");
bitmapIcon = await customBitmapDescriptor(
imageUrl: imageUrl(places[index].photoRef),
title: wordList[0],
);
markers = markerService.getBarMarkers(
places,
markerIcon: this.bitmapIcon,
);
print(markers.isEmpty);
});
【问题讨论】:
-
我需要更多关于 currentPosition 和其他代码的描述。
-
API 正在获取 currentPosition 以获取我的位置,主要是从 APIS 获取的地方和重新添加到这些地方的标记
-
Consumer 用于使用提供的数据构建一个小部件,而不是用它做未来的逻辑,我建议在其他地方做那个逻辑或使用 FutureProvider 而不是消费者然后消费它
标签: flutter dart flutter-provider google-maps-flutter