MimeType class
A MIME type representing the format of content.
MIME types consist of a primary type and a subtype, separated by a slash. They're used to identify the format of content in HTTP headers.
Examples:
// Using predefined constants
final jsonType = MimeType.json; // application/json
final htmlType = MimeType.html; // text/html
final pngType = MimeType('image', 'png'); // image/png
// Parsing from string
final customType = MimeType.parse('application/vnd.api+json');
print(customType.primaryType); // "application"
print(customType.subType); // "vnd.api+json"
// Checking if type is text-based
print(MimeType.json.isText); // true
print(MimeType.octetStream.isText); // false
// Converting to header value
print(MimeType.plainText.toHeaderValue()); // "text/plain"
Constructors
- MimeType(String primaryType, String subType)
-
Creates a new mime type.
const
- MimeType.parse(String type)
-
Parses a mime type from a string.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- isText → bool
-
Returns
trueif the mime type represents text-based content.no setter - primaryType → String
-
The primary type of the mime type.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- subType → String
-
The sub type of the mime type.
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toHeaderValue(
) → String - Returns the value to use for the Content-Type header.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override
Constants
- css → const MimeType
- CSS mime type.
- csv → const MimeType
- CSV mime type.
- html → const MimeType
- HTML mime type.
- javascript → const MimeType
- JavaScript mime type.
- json → const MimeType
- JSON mime type.
- multipartByteranges → const MimeType
- Multipart byteranges mime type.
- multipartFormData → const MimeType
- Multipart form data mime type.
- octetStream → const MimeType
- Binary mime type.
- pdf → const MimeType
- PDF mime type.
- plainText → const MimeType
- Text mime types.
- rtf → const MimeType
- RTF mime type.
- urlEncoded → const MimeType
- URL-encoded form MIME type.
- xml → const MimeType
- XML mime type.