getViewportBoundsOrNull method

Future<LatLngBounds?> getViewportBoundsOrNull()

getViewportBounds for callers that would rather handle a dead map than catch: null means there is no live map to read bounds from.

Implementation

Future<flutter_map.LatLngBounds?> getViewportBoundsOrNull() async {
  final visibleRegion = await _withMap((map) => map.getVisibleRegion());
  if (visibleRegion == null) return null;
  return flutter_map.LatLngBounds.fromPoints([
    visibleRegion.southwest.toLatLng(),
    visibleRegion.northeast.toLatLng(),
  ]);
}