MediaTypeResolver class
Single source of truth for MIME type mapping, extension normalization, media type detection, and MessageType inference from attachments.
Use resolveAttachment whenever building a FileAttachment from raw server data to guarantee consistent extension normalization and MIME derivation.
Use inferMessageType after building attachments to determine the correct MessageType — do not rely on the server's raw type string when attachments are present.
Constructors
- MediaTypeResolver({AttachmentTypeStrategy strategy = const DefaultAttachmentTypeStrategy()})
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- strategy → AttachmentTypeStrategy
-
final
Methods
-
extensionFromFileName(
String fileName) → String -
Extracts the extension from
fileName(no leading dot, lowercase). Returns''if the name has no extension. -
extensionFromMimeType(
String mimeType) → String -
Returns the canonical extension for
mimeType, or''if unrecognized. -
inferMessageType(
List< FileAttachment> attachments) → MessageType - Infers MessageType from a list of FileAttachments.
-
inferMessageTypeFromExtension(
String extension) → MessageType -
inferMessageTypeFromUrl(
String? url, String? mimeType) → MessageType - Infers MessageType from a URL when attachment is uploading.
-
isAudio(
String extension) → bool -
isImage(
String extension) → bool -
isVideo(
String extension) → bool -
mimeTypeFromExtension(
String extension) → String -
Returns the canonical MIME type for
extension. Falls back to'application/octet-stream'for unknown extensions. -
normalizeExtension(
String raw) → String -
Strips a leading dot and lowercases
raw.'.JPG'→'jpg','PDF'→'pdf',''→''. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
resolveAttachment(
{required String id, required String url, required String fileName, String? rawExtension, String? rawMimeType, int size = 0, int? pageCount, String? thumbnailUrl, int? width, int? height, String? thumbhash, String? blurhash, Duration? duration, List< double> ? waveform}) → FileAttachment -
Builds a FileAttachment from raw server data, normalizing
rawExtensionand derivingmimeTypeconsistently. -
resolveExtension(
String rawExtension, {String? fallbackFileName}) → String - Resolves the best extension from an explicit raw extension with a filename fallback.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited