getCachedMediaPath static method

Future<String?> getCachedMediaPath(
  1. String mediaUrl, {
  2. String? cacheSubdirectory,
  3. String? fileNamePrefix,
})

Returns cached path if present, otherwise null.

Implementation

static Future<String?> getCachedMediaPath(
  String mediaUrl, {
  String? cacheSubdirectory,
  String? fileNamePrefix,
}) async {
  try {
    final mediaType = _getMediaType(mediaUrl);
    final extension = _extractExtension(mediaUrl, mediaType);
    final cacheDirectory = await _getCacheDirectory(cacheSubdirectory, createIfMissing: false);
    if (cacheDirectory == null) {
      return null;
    }

    final prefix = fileNamePrefix ?? 'media';
    final file = File('${cacheDirectory.path}/${_buildFileName(mediaUrl, prefix, extension)}');

    return await file.exists() ? file.path : null;
  } catch (e) {
    debugLog('Error getting cached media path: $e');
    return null;
  }
}