ofUri static method
Resolves a format from a content URI and a ContentResolver
.
Accepts the following URI schemes: content, android.resource, file.
Implementation
static Future<MediaType?> ofUri(Uri uri,
{List<String> mediaTypes = const [],
List<String> fileExtensions = const [],
List<Sniffer> sniffers = MediaType.sniffers}) {
List<String> allMediaTypes = List.of(mediaTypes);
List<String> allFileExtensions =
fileExtensions.map((ext) => ext.extension()).toList();
uri.path
.extension()
.takeIf((it) => it.isNotEmpty)
?.let((it) => allFileExtensions.insert(0, it));
SnifferContent content = SnifferUriContent(uri);
return _of(
content: content,
mediaTypes: allMediaTypes,
fileExtensions: allFileExtensions,
sniffers: sniffers);
}