showNewsListDialogAsync function

Future<void> showNewsListDialogAsync({
  1. required BuildContext context,
  2. required MapController mapController,
  3. required GdeltNewsService newsService,
  4. required List<NewsMarker> getVisibleMarkers(),
  5. required void updateState(
    1. List<NewsMarker> markers,
    2. bool loading,
    3. bool show
    ),
})

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,
      ),
    );
  }
}