Giter VIP home page Giter VIP logo

wys619 / al_downloader_flutter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jackleemeta/al_downloader_flutter

0.0 0.0 0.0 428 KB

A URL-based flutter downloader that supports to download any type of file and automatically manages a lot of things.

Home Page: https://github.com/jackleemeta/al_downloader_flutter

License: MIT License

Ruby 2.51% C++ 15.74% C 0.69% Objective-C 0.04% Java 0.13% Dart 68.02% Swift 1.50% HTML 3.67% CMake 7.70%

al_downloader_flutter's Introduction

al_downloader

pub package

A URL-based flutter downloader that supports to download any type of file and automatically manages a lot of things.

If you need Chinese Document, click here.

Features

  • manage download tasks by url
  • simple download status
  • I/O infrequently
  • provide convenient download handle
  • support batch download
  • manage automatically files without requiring to be specified a download path
  • based on flutter_downloader

Integration

Native Config: same as flutter_downloader native config

add the following line to your pubspec.yaml

dependencies:
  al_downloader: ^1.5.7

run the following line with your command line

flutter packages get

import the following line, then you can use al_downloader

import 'package:al_downloader/al_downloader.dart';

Usage

ALDownloader

/// Download
await ALDownloader.download(url,
    downloaderHandlerInterface:
        ALDownloaderHandlerInterface(progressHandler: (progress) {
      debugPrint(
          "ALDownloader | download progress = $progress, url = $url\n");
    }, succeededHandler: () {
      debugPrint("ALDownloader | download succeeded, url = $url\n");
    }, failedHandler: () {
      debugPrint("ALDownloader | download failed, url = $url\n");
    }, pausedHandler: () {
      debugPrint("ALDownloader | download paused, url = $url\n");
    }));
/// Add a downloader handler interface
ALDownloader.addDownloaderHandlerInterface(
    ALDownloaderHandlerInterface(progressHandler: (progress) {
      debugPrint(
          "ALDownloader | download progress = $progress, url = $url\n");
    }, succeededHandler: () {
      debugPrint("ALDownloader | download succeeded, url = $url\n");
    }, failedHandler: () {
      debugPrint("ALDownloader | download failed, url = $url\n");
    }, pausedHandler: () {
      debugPrint("ALDownloader | download paused, url = $url\n");
    }),
    url);
/// Add a forever downloader handler interface
ALDownloader.addForeverDownloaderHandlerInterface(
    ALDownloaderHandlerInterface(progressHandler: (progress) {
      debugPrint(
          "ALDownloader | download progress = $progress, url = $url\n");
    }, succeededHandler: () {
      debugPrint("ALDownloader | download succeeded, url = $url\n");
    }, failedHandler: () {
      debugPrint("ALDownloader | download failed, url = $url\n");
    }, pausedHandler: () {
      debugPrint("ALDownloader | download paused, url = $url\n");
    }),
    url);
/// Remove downloader handler interface
ALDownloader.removeDownloaderHandlerInterfaceForUrl(url);
/// Get download status
final status = ALDownloader.getDownloadStatusForUrl(url);
/// Get download progress
final progress = ALDownloader.getDownloadProgressForUrl(url);
/// Pause download
///
/// Stop download, but the incomplete data will not be deleted.
await ALDownloader.pause(url);
/// Cancel download
///
/// Stop download, and the incomplete data will be deleted.
await ALDownloader.cancel(url);
/// Remove download
///
/// Remove download, and all the data will be deleted.
await ALDownloader.remove(url);

ALDownloaderBatcher

/// Batch download
await ALDownloaderBatcher.downloadUrls(urls,
    downloaderHandlerInterface:
        ALDownloaderHandlerInterface(progressHandler: (progress) {
      debugPrint("ALDownloader | batch | download progress = $progress\n");
    }, succeededHandler: () {
      debugPrint("ALDownloader | batch | download succeeded\n");
    }, failedHandler: () {
      debugPrint("ALDownloader | batch | download failed\n");
    }, pausedHandler: () {
      debugPrint("ALDownloader | batch | download paused\n");
    }));
/// Add a downloader handler interface for batch
ALDownloaderBatcher.addDownloaderHandlerInterface(
    ALDownloaderHandlerInterface(progressHandler: (progress) {
      debugPrint("ALDownloader | batch | download progress = $progress\n");
    }, succeededHandler: () {
      debugPrint("ALDownloader | batch | download succeeded\n");
    }, failedHandler: () {
      debugPrint("ALDownloader | batch | download failed\n");
    }, pausedHandler: () {
      debugPrint("ALDownloader | batch | download paused\n");
    }),
    urls);
/// Get download status for a set of urls
final status = ALDownloaderBatcher.getDownloadStatusForUrls(urls);

ALDownloaderPersistentFileManager - A manager that manages persistent file by url

final model = await ALDownloaderPersistentFileManager
    .lazyGetALDownloaderPathModelForUrl(url);
debugPrint(
    "ALDownloader | get 'physical directory path' and 'virtual/physical file name' of the file for [url], url = $url, model = $model\n");

final path2 = await ALDownloaderPersistentFileManager
    .lazyGetAbsolutePathOfDirectoryForUrl(url);
debugPrint(
    "ALDownloader | get 'physical directory path' for [url], url = $url, path = $path2\n");

final path3 = await ALDownloaderPersistentFileManager
    .getAbsoluteVirtualPathOfFileForUrl(url);
debugPrint(
    "ALDownloader | get 'virtual file path' for [url], url = $url, path = $path3\n");

final path4 = await ALDownloaderPersistentFileManager
    .getAbsolutePhysicalPathOfFileForUrl(url);
debugPrint(
    "ALDownloader | get 'physical file path' for [url], url = $url, path = $path4\n");

final isExist = await ALDownloaderPersistentFileManager
    .isExistAbsolutePhysicalPathOfFileForUrl(url);
debugPrint(
    "ALDownloader | check whether [url] exists a 'physical file path', url = $url, is Exist = $isExist\n");

final fileName = ALDownloaderPersistentFileManager.getFileNameForUrl(url);
debugPrint(
    "ALDownloader | get 'virtual/physical file name' for [url], url = $url, file name = $fileName\n");

ALDownloaderPrintConfig

/// Enable print
ALDownloaderPrintConfig.enabled = true;

/// Disable frequent print
ALDownloaderPrintConfig.frequentEnabled = false;

Note:

1. Method needs to add qualifier await when executing in a coroutine.

For example that

Future<void> executeSomeMethodsTogetherSerially() async {
  await ALDownloader.initialize();
  await ALDownloader.remove(url);
  await ALDownloader.download(url);
}

2. If the persistent file was removed by exceptional means, such as the cache folder being deleted by some business code, call [remove] and then call [download] to re-download for fixing the problem.

Key File Of Example

iOS

Android

Maintainer: jackleemeta ([email protected])

al_downloader_flutter's People

Contributors

jackleemeta avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.