Overview
TheLocalAudiobook class represents an audiobook that has been imported from the user’s device storage. Unlike remote audiobooks from LibriVox, these are managed entirely locally and can include user-added metadata.
Properties
The title of the audiobook
The author of the audiobook
The file system path to the folder containing the audiobook files
The file system path to the cover image, if available
A list of paths to the audio files that make up this audiobook
The total playback duration of all audio files combined
The date and time when this audiobook was added to the library
The date and time when this audiobook was last modified
A text description of the audiobook
The genre or category of the audiobook
User rating for the audiobook
A unique identifier for the audiobook
Constructor
Constructor
Creates a newLocalAudiobook instance.
Parameters:
The title of the audiobook
The author of the audiobook
The folder path containing the audiobook files
The path to the cover image
List of audio file paths
Total duration of the audiobook
When the audiobook was added
When the audiobook was last modified
Description text
Genre or category
User rating
Unique identifier
Getters
firstAudioFile
Returns the path to the first audio file in the audiobook, or null if there are no audio files. Returns:String?
hasCoverImage
Checks whether the audiobook has a cover image. Returns:bool
formattedDuration
Returns a human-readable string representation of the total duration. Returns:String
Format:
- If duration is unknown: “Unknown”
- If hours > 0: “h m”
- If hours = 0: “m”
Methods
copyWith
Creates a copy of the audiobook with optionally updated fields. Parameters:Updated title
Updated author
Updated folder path
Updated cover image path
Updated audio files list
Updated total duration
Updated date added
Updated last modified date
Updated description
Updated genre
Updated rating
Updated identifier
LocalAudiobook
toMap()
Converts the audiobook to a map suitable for Hive storage. Returns:Map<String, dynamic>
Note: DateTime values are converted to milliseconds since epoch, and Duration is converted to milliseconds.
toString()
Returns a string representation of the audiobook. Returns:String
Static Methods
fromMap
Creates aLocalAudiobook instance from a map (typically retrieved from Hive storage).
Parameters:
The map containing LocalAudiobook data (Map<String, dynamic>)
LocalAudiobook
Note: Converts milliseconds back to DateTime and Duration objects. Sets default values for missing fields:
id: Empty stringtitle: Empty stringauthor: “Unknown”folderPath: Empty stringaudioFiles: Empty listdateAdded: Epoch (January 1, 1970)lastModified: Epoch (January 1, 1970)