downloadAndCacheImage static method

Future<String?> downloadAndCacheImage(
  1. String remoteUrl
)

Implementation

static Future<String?> downloadAndCacheImage(String remoteUrl) async {
  try {
    final response = await _dio.get<List<int>>(remoteUrl, options: Options(responseType: ResponseType.bytes));

    if (response.data != null) {
      final bytes = Uint8List.fromList(response.data!);
      final key = sha1.convert(utf8.encode(remoteUrl)).toString();
      return await storeImage(key, bytes);
    }
  } catch (e) {
    debugPrint('⚠️ [ImageDownloader] Failed to cache image for $remoteUrl: $e');
  }

  return remoteUrl; // Return fallback remote URL on failure
}