download_assets 패키지는 Flutter 애플리케이션에서 앱의 저장소 내에 자산을 로컬로 다운로드하고 저장하여 오프라인 사용이 가능하게 합니다. 원격 URL에서 파일을 다운로드하여 장치의 파일 시스템에 저장할 수 있으며, 이미지, 문서 또는 구성 파일과 같은 리소스를 캐시하는 데 특히 유용합니다. 이 패키지는 Android, iOS, macOS, Windows, Linux 등 여러 플랫폼에서 작동하며 일관된 동작을 보장합니다. 비동기 다운로드 처리와 자동 파일 경로 관리를 통해 자산 관리를 간소화합니다.
사용 사례
오프라인 콘텐츠 액세스
원격 리소스 캐싱
앱 자산 사전 로드
동적 콘텐츠 업데이트
자산 백업 메커니즘
주요 기능
크로스 플랫폼 지원
비동기 다운로드
로컬 파일 저장
자동 경로 관리
다양한 파일 형식 지원
적합한 대상
오프라인 기능이 필요한 앱
콘텐츠 중심 앱
동적 자산 전달을 지원하는 앱
원격 자산을 관리하는 개발자
캐시된 데이터가 필요한 프로젝트
고려 사항
모바일에서 인터넷 권한이 필요합니다
디스크 공간 관리 필요
파일 이름 충돌 가능성
내장된 재시도 로직 없음
다운로드된 파일 수동 정리
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Download_assets
About
The download_assets package is a powerful library that facilitates the process of downloading assets
into the application. With this library, you can easily download files, images, videos, and other
resources in your app, providing a smooth and efficient user experience.
Features
init
Init method for setting up the assetsDir, which is required to be called during app
initialization.
await downloadAssetsController.init();
startDownload
Starts the asset download process.
assetsUrls: A list of [AssetUrl] objects representing each file to be downloaded.
uncompressDelegates: A list of custom decompression delegates for different types of files, such
as ZIP, RAR, etc (optional).
onStartUnzipping: Called right before the start of the uncompressing process (optional).
onProgress: Called after each iteration returning the current progress (optional). The double parameter ranges from 0 to 1, where 1 indicates the completion of the download process.
onDone: Called when all files have been downloaded and uncompressed (optional).
onCancel: Cancels the ongoing download (optional).
requestQueryParams: Query params to be used in the request (optional).
requestExtraHeaders: Extra headers to be added in the request (optional).
checkSize: Specifies if the size of the file should be checked first before starting download (optional).
Uncompress delegates are responsible for implementing the logic to uncompress different types of
files, such as ZIP, RAR, etc. By providing a list of delegates, it becomes possible to support
multiple file formats during the download.
To implement your own uncompression delegate, you should implement the interface below.
/// Abstract class representing a delegate for asset decompression.abstractclassUncompressDelegate{
constUncompressDelegate();
/// Gets the file extension associated with the delegate.Stringgetextension;
/// uncompress the asset located at [compressedFilePath] to the specified [assetsDir]./// [compressedFilePath] -> The path to the compressed asset file./// [assetsDir] -> The directory where the uncompressed asset should be stored.Futureuncompress(String compressedFilePath, String assetsDir);
}
Note: This kind of delegate is essential for enabling the download process to handle various
file formats by implementing the necessary decompression logic. This flexibility allows users to
download and work with a wide range of compressed file types effortlessly. UnzipDelegate() is
already included, which handles the decompression of ZIP files.
Example
You can find an example here: https://github.com/edjostenes/download_assets/tree/master/example
Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvement,
please create an issue on the GitHub repository.