isolated_download_manager 1.0.3 copy "isolated_download_manager: ^1.0.3" to clipboard
isolated_download_manager: ^1.0.3 copied to clipboard

File download manager based on reusable isolates with progress, cancellation, pause and resume

example/isolated_download_manager_example.dart

import 'dart:io' show exit;
import 'package:isolated_download_manager/isolated_download_manager.dart';

void main() async {
  // Initialize
  await DownloadManager.instance.init(
    isolates: 3,
  );

  // Download
  final request = DownloadManager.instance
      .download("https://golang.org/dl/go1.19.1.src.tar.gz", path: "Go.tar.gz");

  // Listen
  request.events.listen((event) {
    if (event is DownloadState) {
      print("event: $event");
      if (event == DownloadState.finished) dispose();
    } else if (event is double) {
      print("progress: ${(event * 100.0).toStringAsFixed(0)}%");
    }
  }, onError: (error) {
    print("error $error");
    dispose();
  });

  // Methods
  await Future.delayed(const Duration(milliseconds: 1500));
  request.pause();
  await Future.delayed(const Duration(milliseconds: 1500));
  request.resume();
  await Future.delayed(const Duration(milliseconds: 1500));
  request.cancel();

  // Properties
  print(request.progress);
  print(request.isPaused);
  print(request.isCancelled);

  // Static methods
  print(DownloadManager.instance.queue); // list queued requests
  DownloadManager.instance.cancelAll(); // cancel all downloads
}

// Clean-up isolates and exit
void dispose() => DownloadManager.instance.dispose().then((_) => exit(0));
27
likes
160
pub points
82%
popularity

Publisher

verified publisherstarkdev.org

File download manager based on reusable isolates with progress, cancellation, pause and resume

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

download_task, http

More

Packages that depend on isolated_download_manager