media_source 1.3.0
media_source: ^1.3.0 copied to clipboard
Type-safe, cross-platform media handling for files, memory, asset, and network sources with automatic type detection, seamless conversions, and Flutter integration.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
1.3.0 - 2025-12-14 #
1.2.0 - 2025-12-14 #
Added #
- ThumbnailMediaSource - A wrapper source that pairs high-quality media with a lightweight thumbnail
- Supports separate types for original and thumbnail generic types (e.g.
ThumbnailMediaSource<VideoType, ImageType>) - Automatically delegates metadata (name, size, mimeType) to the original source
- Documentation and examples included
- Supports separate types for original and thumbnail generic types (e.g.
1.1.0 - 2025-11-26 #
Changed #
- Breaking Change: Renamed dependency
sized_filetofile_sized - Breaking Change: Renamed
SizedFileclass toFileSize
1.0.0 - 2025-11-06 #
Added #
- AssetMediaSource - New media source for Flutter asset bundles
AssetMediaSource<M>base class for asset-based mediaVideoAssetMedia- Load video assets with duration metadataAudioAssetMedia- Load audio assets with duration metadataImageAssetMedia- Load image assetsDocumentAssetMedia- Load PDF document assetsOtherTypeAssetMedia- Load other file type assets- All asset media types support:
.load()factory method with optionalAssetBundleparameterassetPathproperty for asset locationconvertToMemory()for converting to memory-based mediasaveTo()for saving assets to file system- Pattern matching with
fold()including newassetcallback - Lazy loading with optional size parameter to optimize performance
- Interactive Flutter example app (
example/asset_media_example.dart)- Complete MaterialApp demonstrating all asset media features
- 7 interactive examples: video, audio, image, document, conversions, metadata preservation, and pattern matching
- UI with buttons to run each example scenario
- Detailed usage comments and pubspec.yaml asset configuration guide
- Console examples for asset media in
example/main.dart- Example 4: Asset Media Sources with load, convert, and save demonstrations
- Shows optimized loading with size hints
- Demonstrates conversion chains (asset โ memory โ file)
- Comprehensive test coverage for AssetMediaSource
- 52 tests with 100% coverage for asset media functionality
TestFileAssetBundlefor testing asset loading- Tests for all asset media types and operations
- Fixture-based test data with real asset files
Changed #
- Updated
MediaSource.fold()to includeassetcallback parameter- Added
assetparameter to support asset media pattern matching - Maintains backward compatibility with
orElsefallback
- Added
- Enhanced README.md with comprehensive asset media documentation
- Added "Working with Asset Media Source" section with code examples
- Updated features list to include asset media support
- Updated motivation section to mention bundled assets
- Added asset media feature highlights (6 key features)
- Updated all
fold()examples to includeassetparameter - Added AssetMediaSource to API Reference section
- Included link to interactive Flutter example
- Updated package description to include "asset" sources
- Improved extensibility documentation for custom media sources
- Updated all code examples and documentation to include
assetparameter infold()calls- Main library documentation (
lib/media_source.dart) - README examples (Complete Example, Pattern Matching sections)
- Console examples (
example/main.dart) - Asset media example with pattern matching demonstration
- Main library documentation (
Documentation #
- Comprehensive dartdoc comments for all AssetMediaSource classes
- Usage examples in class-level documentation
- Parameter descriptions for all factory methods
- Examples showing load(), saveTo(), and convertToMemory() patterns
- Cross-references between related asset media types
0.2.0-alpha.6 #
Added #
- Custom media factory pattern documentation and examples
- Added
MediaFactoryclass example for centralized media creation - Added
SmartMediaFactoryclass with size-based optimization logic - New Example 7 in
example/main.dartdemonstrating factory patterns - Factory implementations showing auto-detection from paths and URLs
- Business logic examples (memory vs. file based on size thresholds)
- Added
- Enhanced extensibility documentation
- Added custom media factory section in README.md with code examples
- Updated library documentation to mention three extensibility approaches
- Highlighted benefits: centralization, business rules, testing, optimization
Changed #
- Updated README.md with custom media factory examples
- Added
MediaSourceTypeenum example - Added basic and smart factory implementation examples
- Included practical benefits list for factory pattern
- Added
- Enhanced library-level documentation in
media_source.dart- Added factory pattern as third extensibility option
- Included factory code example in main library docs
- Improved README formatting with more bold highlights for important terms
Fixed #
- Added
homepagefield topubspec.yamlfor better pub.dev compatibility
0.2.0-alpha.5 #
Fixed #
- GitHub Actions CI workflow now properly checks out repository code
- CI pipeline now successfully runs analysis, tests, and coverage reporting
- Set Flutter version to 3.24.0 for better compatibility
- Simplified CI dependencies installation step by removing debug commands
0.2.0-alpha.4 #
Fixed #
- WASM compatibility issue by updating conditional import from
dart.library.htmltodart.library.js_interop- Package is now fully compatible with WASM runtime
- Maintains backward compatibility with web and native platforms
- Resolves pub.dev scoring penalty for WASM incompatibility
0.2.0-alpha.3 - 2025-11-05 #
Added #
- Comprehensive inline documentation for all public APIs
- Class-level documentation for all media types and sources
- Method and constructor documentation with parameter descriptions
- Property documentation explaining purpose and usage
- Usage examples in doc comments
- Extensibility documentation
- Guide for creating custom media types by extending
FileTypeImpl - Guide for creating custom media sources by extending
MediaSource<M> - Example implementations in library docs and README
- Guide for creating custom media types by extending
- Complete example file (
example/main.dart) demonstrating:- Working with file, memory, and network media sources
- Type-safe pattern matching with fold
- Converting between different source types
- Creating custom media types and sources
- Platform utilities documentation
- Documented
PlatformUtilsfacade pattern - IO and web implementation documentation
- Cross-platform file operation guides
- Documented
- Extension methods documentation
FileExtensionsonXFilewith usage examplesUriExtensionsfor file name extractionObjectExtensionfor safe type casting
Changed #
- Enhanced library-level documentation in
media_source.dart- Added comprehensive feature list
- Added usage examples for all source types
- Added pattern matching examples
- Included extensibility section with custom type example
- Improved README.md
- Added motivation section inspired by Flutter's
ImageProvider - Added extensibility section with practical examples
- Added quick start link to example file
- Better organization of features and usage patterns
- Added motivation section inspired by Flutter's
Documentation #
- All public classes now have comprehensive doc comments
- All public methods include parameter and return value documentation
- IDE tooltips and generated docs are now complete
- Code comments explain design patterns (fold, facade, etc.)
Fixed #
- WASM compatibility issue by updating conditional import from
dart.library.htmltodart.library.js_interop- Package is now compatible with WASM runtime
- Maintains backward compatibility with web and native platforms
0.2.0-alpha.2 #
Added #
- Comprehensive test coverage achieving 99.7% coverage
- Tests for
UrlMediaclass with bothUriand.url()constructors - Tests for
.url()constructors in all network media types - Test for
FileMediaSourcefold method callback - Test for
DocumentTypefold method callback - Test for
UrlTypefold method callback - Test for
stringifyproperty inMemoryMediaSource - Test for
propsproperty inFileMediaSource - Test for
moveTo()when target file already exists - Extended documentation in main library file with usage examples
Changed #
- Refactored
DurationMediafrom abstract class with constructor to interface-only (getter pattern) - Simplified
VideoFileMedia.fromFile()to use inline null-coalescing instead of try-catch - Improved
FileMediaSource.fromPath()to explicitly handle size parameter conversion - Removed unused
dart:developerimport fromfile_media_source.dart
Fixed #
- All test assertions now use direct comparison instead of deprecated
equals()matcher - Error handling in file operations now more consistent across media types
Testing #
- Added 13 new test cases across multiple test files
- Total test count: 157 tests (155 passing, 2 skipped)
- Test coverage improved from ~91% to 99.7%
- Comprehensive coverage of all media source types and operations
0.1.0-alpha.1 - 2025-11-03 #
Added #
- Initial release of the
media_sourcepackage - Core
MediaSourceabstraction for handling different media sources FileMediaSourceimplementation for local file system access- Support for file operations (delete, exists, size)
- Automatic MIME type detection
MemoryMediaSourceimplementation for in-memory media data- Support for
Uint8Listbyte arrays - MIME type detection from byte headers
- Support for
NetworkMediaSourceimplementation for remote URL media- URL validation and parsing
- Automatic media type detection from URLs
MediaTypeclassification system with subtypes:ImageType- for image filesAudioType- for audio files with duration supportVideoType- for video files with duration supportDocumentType- for PDF documentsUrlType- for URL referencesOtherType- for unclassified files
- Media type detection from:
- File paths using MIME type lookup
- MIME type strings
- Byte data headers
- File utilities (
file_util.dart):getMimeTypeFromPath()- detect MIME from file pathgetMimeTypeFromBytes()- detect MIME from byte datagetFileMetadata()- extract duration and MIME from media filesgetFileMetadataFromBytes()- extract metadata from byte arrays
- MIME groups utility (
mime_groups.dart):- Extension to
MediaTypemapping derived frommimepackage - Grouped extension sets by media type
- Pre-built sets:
imageExtensions,audioExtensions,videoExtensions,documentExtensions,otherExtensions - Helper functions:
mediaTypeForExtension()- get MediaType from file extensionisExtensionOfType()- check if extension matches a MediaType
- Runtime classification of all extensions from the
mimepackage's default extension map
- Extension to
- Cross-platform support:
- Platform-specific utilities for web and native (IO)
- Conditional imports for Flutter web compatibility
- File extensions on
XFile:delete()- delete file with existence checksize()- get file sizeexists()- check file existencemediaType- get MediaType from filename- get file name from path
- Comprehensive test suite:
MediaTypetests for classification and type detectionMemoryMediaSourcetestsNetworkMediaSourcetests with URL validation- Test fixtures and sample files
Features #
- ๐ฏ Type-safe media source abstraction
- ๐ Support for file, memory, and network media sources
- ๐ Automatic media type detection from paths, MIME types, and bytes
- ๐ Cross-platform support (Flutter mobile, web, desktop)
- ๐ Comprehensive MIME type to media type mapping
- ๐งฉ Extension-based media type lookup utilities
- ๐งช Test coverage for core functionality
- ๐ Built on
cross_filefor cross-platform file handling - โก Lightweight with minimal dependencies