fetchNewsForBounds function
- required BuildContext context,
- required MapController mapController,
- required GdeltNewsService newsService,
- required void updateState(
- List<
NewsMarker> markers, - bool loading
- List<
Fetches news for current map bounds.
Implementation
Future<void> fetchNewsForBounds({
required BuildContext context,
required MapController mapController,
required GdeltNewsService newsService,
required void Function(List<NewsMarker> markers, bool loading) updateState,
}) async {
// Don't clear existing markers, just set loading state
// Get current cached markers first.
final bounds = mapController.camera.visibleBounds;
final currentMarkers = newsService.getMarkersInBounds(bounds);
updateState(currentMarkers, true);
try {
final nm = await newsService.fetchNews(
bounds: bounds,
query: 'news',
maxResults: 50,
timeSpan: '24h',
);
updateState(nm, false);
} catch (e) {
updateState([], false);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to fetch news: $e'),
backgroundColor: Colors.red.shade700,
),
);
}
}