Orientação gerada a partir de informações públicas. Apenas para referência.
O pacote download_assets permite que aplicativos Flutter recuperem e armazenem ativos localmente no repositório do aplicativo, tornando-os disponíveis para uso offline. Ele suporta o download de arquivos a partir de URLs remotas e seu salvamento no sistema de arquivos do dispositivo, sendo especialmente útil para cache de recursos como imagens, documentos ou arquivos de configuração. O pacote funciona em múltiplas plataformas, incluindo Android, iOS, macOS, Windows e Linux, garantindo comportamento consistente. Simplifica a gestão de ativos ao lidar com downloads assíncronos e gerenciar caminhos de arquivos automaticamente.
Casos de uso
Acesso a conteúdo offline
Armazenar em cache recursos remotos
Pré-carregar ativos do aplicativo
Atualizações de conteúdo dinâmico
Mecanismos de fallback de recurso
Principais recursos
Suporte multiplataforma
Downloads assíncronos
Armazenamento de arquivos locais
Gerenciamento automático de caminhos
Suporte para vários tipos de arquivos
Indicado para
Aplicativos que precisam de funcionalidade offline
Aplicativos com conteúdo intenso
Aplicativos com entrega dinâmica de recursos
Desenvolvedores gerenciando ativos remotos
Projetos que exigem dados em cache
Considerações
Requer permissão de internet no mobile
Gerenciamento de espaço em disco necessário
Conflitos de nome de arquivo possíveis
Sem lógica de retry embutida
Limpeza manual de arquivos baixados
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
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.