updateNewsFromCacheForBounds function
- required MapController mapController,
- required GdeltNewsService newsService,
- required void setMarkers(),
- required Future<
void> fetchForCurrentBounds(),
Updates news markers from cache when map position changes.
Implementation
void updateNewsFromCacheForBounds({
required MapController mapController,
required GdeltNewsService newsService,
required void Function(List<NewsMarker>) setMarkers,
required Future<void> Function() fetchForCurrentBounds,
}) {
final bounds = mapController.camera.visibleBounds;
final cached = newsService.getMarkersInBounds(bounds);
// Always update visible markers from cache.
if (cached.isNotEmpty) {
setMarkers(cached);
}
// Only fetch new data if significantly outside cached bounds
// This prevents unnecessary fetches during small movements.
if (!newsService.isBoundsCovered(bounds)) {
// Async fetch without blocking UI.
fetchForCurrentBounds();
}
}