fetchMap static method

Future<Map<String, dynamic>?> fetchMap(
  1. Uri uri
)

Fetches a JSON map from a URI. Returns null if the request fails or decoding fails.

Implementation

static Future<Map<String, dynamic>?> fetchMap(Uri uri) async {
  try {
    final response = await http.get(uri);
    if (response.statusCode != 200) return null;

    final body = response.body.trim();

    if (body.startsWith('<!DOCTYPE html') || body.startsWith('<html')) {
      return null;
    }

    final decoded = json.decode(body);
    if (decoded is Map<String, dynamic>) return decoded;
  } catch (_) {
    // Silent fail - return null
  }
  return null;
}