showNewsListDialogAsync function
- required BuildContext context,
- required MapController mapController,
- required GdeltNewsService newsService,
- required List<
NewsMarker> getVisibleMarkers(), - required void updateState(
- List<
NewsMarker> markers, - bool loading,
- bool show
- List<
Shows news list dialog and handles news marker operations.
Implementation
Future<void> showNewsListDialogAsync({
required BuildContext context,
required MapController mapController,
required GdeltNewsService newsService,
required List<NewsMarker> Function() getVisibleMarkers,
required void Function(List<NewsMarker> markers, bool loading, bool show)
updateState,
}) async {
updateState([], true, true);
try {
final bounds = mapController.camera.visibleBounds;
final nm = await newsService.fetchNews(
bounds: bounds,
query: 'news',
maxResults: 50,
timeSpan: '24h',
);
updateState(nm, false, true);
if (!context.mounted) return;
await showNewsListDialog(
context: context,
visibleNewsMarkers: getVisibleMarkers(),
onCloseNews: () => updateState([], false, false),
onNewsMarkerTap: (n) {
mapController.move(n.location, 12.0);
Future.delayed(const Duration(milliseconds: 300), () {
if (context.mounted) {
showNewsMarkerDetailsSheet(context, n);
}
});
},
);
} catch (e) {
updateState([], false, false);
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Failed to fetch news: $e'),
backgroundColor: Colors.red.shade700,
),
);
}
}