パッケージ、リポジトリ、アプリカテゴリを検索

GitHub リポジトリedjostenes/download_assets

アセットをダウンロードする

Flutterで開発されたこのパッケージは、アプリに含まれていないすべてのアセットをローカルストレージにダウンロードして展開します。

アセットをダウンロードする のプロジェクト画像
スター
25
フォーク
18
最終プッシュ(UTC)
2025/12/17
プロジェクト状態
公開中

元の README

以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。

style: lint

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).
await downloadAssetsController.startDownload(
    onCancel: () {
        //TODO: implement cancel here
    },
    assetsUrls: [
      AssetUrl(url: 'https://github.com/edjostenes/download_assets/raw/main/download/image_1.png'),
      AssetUrl(url: 'https://github.com/edjostenes/download_assets/raw/main/download/assets.zip'),
      AssetUrl(url: 'https://github.com/edjostenes/download_assets/raw/main/download/image_2.png'),
      AssetUrl(url: 'https://github.com/edjostenes/download_assets/raw/main/download/image_3.png'),
    ],
    onProgress: (progressValue) {
        //TODO: Implement progress here
    },
    onDone: () {
      //TODO: Implement progress here
    }
);
AssetUrl

You can now specify the file name and extension with the AssetUrl class in case you don't have control over the URL format.

class AssetUrl {
  final String url;
  final String? fileName;

  const AssetUrl({
    required this.url,
    this.fileName,
  });
}
clearAssets

Removes all downloaded assets from local storage.

await downloadAssetsController.clearAssets();
getAssetFromWeb
await downloadAssetsController.getAssetFromWeb('<file_name>.<file_extension>');

Note: This method is only available on web version

assetsDir

Path to the files.

File('${downloadAssetsController.assetsDir}/<file_name>.<file_extension>');
assetsDirAlreadyExists

Returns true if the assetsDir path exists.

return await downloadAssetsController.assetsDirAlreadyExists();
assetsFileExists

Returns true if the file exists.

return await downloadAssetsController.assetsFileExists(<file_name>);

Uncompress delegate

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.
abstract class UncompressDelegate {
  const UncompressDelegate();

  /// Gets the file extension associated with the delegate.
  String get extension;

  /// 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.
  Future uncompress(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.

Edjostenes GitHub avatar
GitHub 作者

Edjostenes ↗

言語DartRubyHTMLSwiftKotlinObjective-C

このリポジトリが公開するパッケージ

使用している依存関係

依存関係一覧 10 件

プロジェクトに合うリポジトリを選ぶには?

用途で絞り込み、開発状況を比較し、採用前に元のリポジトリで要件を確認しましょう。

  1. 名前・作者・説明で検索し、技術トピックで絞り込みます。
  2. スター、フォーク、最近のプッシュを比較します。スターは関心の目安であり、品質の保証ではありません。
  3. 利用前に GitHub で README、ライセンス、Issues を確認します。

情報源と管理

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗