AdaptiveFile class
Represents a cross-platform media file with rich metadata, lazy byte loading, format conversion, and disk/memory helpers.
Constructors
- AdaptiveFile({String? path, required String name, Uint8List? bytes, String? mimeType, int? width, int? height, int? size, DateTime? lastModified})
-
Creates a new AdaptiveFile instance.
const
- AdaptiveFile.fromBytes(Uint8List bytes, {required String name, String? mimeType, int? width, int? height, int? size, DateTime? lastModified})
-
Creates an AdaptiveFile from raw in-memory bytes.
factory
- AdaptiveFile.fromMap(Map map)
-
Creates an AdaptiveFile from a Map (e.g. from MethodChannel).
factory
- AdaptiveFile.fromPath(String path, {String? name, String? mimeType, int? width, int? height, int? size, Uint8List? bytes, DateTime? lastModified})
-
Creates an AdaptiveFile from a local file path.
factory
Properties
- aspectRatio → double?
-
Returns the aspect ratio (width / height) if dimensions are known.
no setter
- bytes → Uint8List?
-
In-memory byte buffer (optional / cached).
final
- extension → String
-
Returns the file extension in lowercase without leading dot (e.g. "jpg").
no setter
- extensionWithDot → String
-
Returns the file extension in lowercase with leading dot (e.g. ".jpg").
no setter
- formattedSize → String
-
Returns a human-readable formatted file size string (e.g. "1.4 MB", "340 KB").
no setter
- hasBytes → bool
-
Whether bytes are already loaded in memory.
no setter
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasPath → bool
-
Whether the file is backed by a local filesystem path.
no setter
- height → int?
-
Height of the image in pixels, if known.
final
- lastModified → DateTime?
-
Last modified timestamp, if known.
final
- mimeType → String?
-
MIME type string (e.g. "image/jpeg", "image/png", "image/webp").
final
- name → String
-
The name of the file including extension (e.g. "photo.jpg").
final
- nameWithoutExtension → String
-
Returns the file name without extension.
no setter
- path → String?
-
The local filesystem path of the file, or null if in-memory/web.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → int?
-
Size of the file in bytes, if known.
final
- width → int?
-
Width of the image in pixels, if known.
final
Methods
-
copy(
String newPath) → Future< AdaptiveFile> - Copies the file to a new path.
-
copyWith(
{String? path, String? name, Uint8List? bytes, String? mimeType, int? width, int? height, int? size, DateTime? lastModified}) → AdaptiveFile - Returns a copy of this file with modified attributes.
-
delete(
) → Future< bool> - Deletes the file if it exists on disk.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
readAsBytes(
) → Future< Uint8List> - Reads and returns the raw file bytes. If bytes are already cached in memory, returns them immediately. Otherwise, reads from the local filesystem path on IO platforms.
-
readAsBytesSync(
) → Uint8List? - Synchronously reads the file bytes if in-memory, or from filesystem on IO.
-
saveTo(
String destinationPath) → Future< AdaptiveFile> - Saves the file bytes to a local destination file path. Returns a new AdaptiveFile pointing to the saved destination.
-
saveToBrowser(
) → Future< void> - Triggers a browser file download saving the file to the user's local Downloads folder on Web.
-
saveToDirectory(
String directoryPath) → Future< AdaptiveFile> -
Saves the file into a directory folder using its current name.
Returns a new AdaptiveFile pointing to the saved file in
directoryPath. -
toMap(
) → Map< String, dynamic> - Serializes to a Map representation.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override