ofUri static method

Future<MediaType?> ofUri(
  1. Uri uri, {
  2. List<String> mediaTypes = const [],
  3. List<String> fileExtensions = const [],
  4. List<Sniffer> sniffers = MediaType.sniffers,
})

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);
}