Cached Remote File

style: very good analysis Powered by Mason License: MIT codecov Release Workflow

CachedRemoteFile is a Flutter package for fetching remote files and caching them locally. It allows you to download files from the internet and store them locally, enhancing performance and reducing data usage. This Package is inspired by internet_file

Installation

Install via flutter pub add:

dart pub add cached_remote_file

Then, run flutter pub get to fetch the package.


Usage

Import the package and create an instance of CachedRemoteFile to start fetching and caching remote files.


import 'package:cached_remote_file/cached_remote_file.dart';

// Create a CachedRemoteFile instance
final cachedRemoteFile = CachedRemoteFile();

// Fetch a remote file and store it locally
final url = 'https://example.com/your-remote-file.txt';

try {
  final fileData = await cachedRemoteFile.get(url);
  if (fileData != null) {
    // Handle the downloaded file data (Uint8List)
  }
} catch (e) {
  // Handle errors
}

You can customize the behavior of the get method by providing optional parameters, such as headers, progress callbacks, and more.


// Example with optional parameters
final url = 'https://example.com/your-remote-file.txt';
final headers = {'Authorization': 'Bearer your_access_token'};

try {
  final fileData = await cachedRemoteFile.get(
    url,
    headers: headers,
    force: false,
    method: 'GET',
    timeout: const Duration(seconds: 30),
    downloadProgressValue: (double percentage) {
      // Handle download progress
    },
  );
  if (fileData != null) {
    // Handle the downloaded file data (Uint8List)
  }
} catch (e) {
  // Handle errors
}

Documentation

For detailed information on the package and its classes, please refer to the Dart documentation.

License

This package is distributed under the MIT License. See the LICENSE file for more details.

Libraries

cached_remote_file
A simple package to download and cache file from internet