GithubHelp home page GithubHelp logo

jackleemeta / al_downloader_flutter Goto Github PK

View Code? Open in Web Editor NEW
31.0 2.0 12.0 703 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 1.35% Swift 0.81% Objective-C 0.02% Dart 76.19% HTML 0.91% CMake 9.41% C++ 10.52% C 0.72% Kotlin 0.07%
flutter ios dart download android downloader pub

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.8.4

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

Initialize

ALDownloader.initialize();

Configure print

ALDownloader.configurePrint(true, frequentEnabled: false);

Download

ALDownloader.download(url,
    directoryPath: directoryPath,
    fileName: fileName,
    handlerInterface:
        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 handler interface

ALDownloader.addHandlerInterface(
    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 handler interface

ALDownloader.addForeverHandlerInterface(
    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 handler interface

ALDownloader.removeHandlerInterfaceForUrl(url);

Pause download

/// Stop download, but the incomplete data will not be deleted.
ALDownloader.pause(url);

Cancel download

/// Stop download, and the incomplete data will be deleted.
ALDownloader.cancel(url);

Remove download

/// Remove download, and all the data will be deleted.
ALDownloader.remove(url);

Get download status

final status = await ALDownloader.getStatusForUrl(url);

Get download progress

final progress = await ALDownloader.getProgressForUrl(url);

Get task

final task = await ALDownloader.getTaskForUrl(url);

Get all tasks

final tasks = await ALDownloader.tasks;

ALDownloaderBatcher

Batch download

ALDownloaderBatcher.download(urls,
    handlerInterface:
        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 handler interface for batch

ALDownloaderBatcher.addHandlerInterface(
    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 = await ALDownloaderBatcher.getStatusForUrls(urls);

Get tasks

final tasks = await ALDownloaderBatcher.getTasksForUrls(urls);

ALDownloaderFileManager - A manager that manages file by url

final physicalFilePath =
    await ALDownloaderFileManager.getPhysicalFilePathForUrl(url);
debugPrint(
    'ALDownloader | get physical file path for [url], url = $url, path = $physicalFilePath\n');

Note:

1. 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

Contributing

Welcome contribution!

Welcome to open issue or PR for any problem, suggestion and idea!

Maintainer: jackleemeta ([email protected])

al_downloader_flutter's People

Contributors

jackleemeta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

al_downloader_flutter's Issues

batch download Headers support?

The package is very easy to use and convenient in most cases but I am wondering if it supports headers for batch download?

BackgroundIsolateBinaryMessenger.ensureInitialized

Launching lib/main.dart on Web Server in debug mode...
Waiting for connection from debug service on Web Server...
/home/.pub-cache/hosted/pub.dev/al_downloader-1.7.4/lib/src/internal/ALDownloaderIsolate.dart:15:38: Error: Member not found: 'BackgroundIsolateBinaryMessenger.ensureInitialized'.
BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken);
^^^^^^^^^^^^^^^^^
Waiting for connection from debug service on Web Server... 38.3s
Failed to compile application

Unhandled Exception: Bad state: Stream has already been listened to.

Unhandled Exception: Bad state: Stream has already been listened to.
E/flutter (17234): #0 _StreamController._subscribe (dart:async/stream_controller.dart:676:7)
E/flutter (17234): #1 _ControllerStream._createSubscription (dart:async/stream_controller.dart:827:19)
E/flutter (17234): #2 _StreamImpl.listen (dart:async/stream_impl.dart:471:9)
E/flutter (17234): #3 _ReceivePortImpl.listen (dart:isolate-patch/isolate_patch.dart:92:31)
E/flutter (17234): #4 ALDownloader._addIsolateNameServerPortService (package:al_downloader/src/ALDownloader.dart:470:18)
E/flutter (17234): #5 ALDownloader.initialize (package:al_downloader/src/ALDownloader.dart:21:7)
E/flutter (17234):
E/flutter (17234): #6 ALDownloader.download (package:al_downloader/src/ALDownloader.dart:54:5)
E/flutter (17234):

Changing max concurrent number programmatically

Is it possible to change the maximum number of concurrent (downloading files) at the same time?

If yes, how?

Else, Is it possible to implement it? How much time will it take?

Thanks in advance.

文件删除了无法重新下载

下载文件后,每次启动清理了历史下载,但再次下载时无法进行下载

I/flutter (15793): ALDownloader | _innerRemove, url = https://static.eduzhixin.com/android-apks/forum/zhixinForum_1.0.0.apk, but url's task is null
[log] 下载状态,下载前 ALDownloaderStatus.unstarted
I/flutter (15793): ALDownloader | _getTaskFromUrl, error = Bad state: No element
I/flutter (15793): ALDownloader | _addTaskOrUpdateTaskForUrl, error = Bad state: No element
I/flutter (15793): _ALDownloaderFilePathManager | get external storage directory: /storage/emulated/0/Android/data/com.eduzhixin.appstore.zhixin_pad_appstore/files
I/flutter (15793): ALDownloader | a download task was generated, download status = enqueued, taskId = 87dcf0d8-8362-4dae-b5ac-5ebaa5359549

使用文档

能否加上使用文档跟demo,下载源码好像没有demo

Download issue.

Debug says that download sucseeded but i cant find file on the phone. Whats that?

Header Fields

Using the header fields (for example for auth) of the flutter_downloader plugin would be very helpful.

Example app not working

Hello, when I try to run the example app, all downloads immediately fail? I load up the app and all of the download tasks fail instantly. When I press the remove button then download, they also fail instantly.

More details:

  • ALDownloader 1.5.9
  • Flutter mode: release (working in debug)
  • Android 13 on Pixel 4 XL

aldownloader_log.txt

I tried the example app in flutter_downloader and downloads are working in release mode.

ALDownloader | try to download url, but the url is enqueued

ALDownloader.addForeverDownloaderHandlerInterface(
ALDownloaderHandlerInterface(progressHandler: (progress) {
}, succeededHandler: () {
}, failedHandler: () {
hideLoading();
}, pausedHandler: () {
}),
url);

await ALDownloader.download(url,);

ALDownloader | try to download url, but the url is enqueued, url = ..., taskId = 1601dcc0-42f3-48e1-824a-eedba8cdaf7f

I am trying to download file from url but it is showing this again and again in log.
File is downloaded already and it is showing above message.
But I didn't catch any callback or log till file is downloaded.
How can I get status and control them ?
Thanks.

偶现下载失败,日志打印如下

感觉像是首次安装下载出现,但是并不一定,看下载download progress = -0.01,作者遇到过吗?

使用的是 al_downloader: ^1.7.4

I/DpmTcmClient(21016): RegisterTcmMonitor from: $Proxy1 I/WM-WorkerWrapper(21016): Worker result SUCCESS for Work [ id=e5a74ab2-89ba-4983-a545-8e05e9c5abdf, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ] I/flutter (21016): ALDownloader | download progress = 0.0, url = http://xxxx/drap/drap/1d13a23a-86b2-403d-a616-61be35de1dce.pdf I/flutter (21016): I/flutter (21016): ALDownloader | download progress = -0.01, url = http://xxxx/drap/drap/1d13a23a-86b2-403d-a616-61be35de1dce.pdf I/flutter (21016): I/flutter (21016): ALDownloader | download failed, url = http://xxx/drap/drap/1d13a23a-86b2-403d-a616-61be35de1dce.pdf I/flutter (21016):

编译报错Unresolved reference: TaskDbHelper

编译报错:

Running Gradle task 'assembleRelease'...                        
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt:62:27 Unresolved reference: TaskDbHelper
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt:136:20 Unresolved reference: TaskDbHelper
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt:148:20 Unresolved reference: TaskDbHelper
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/DownloadWorker.kt:446:38 Unresolved reference: IntentUtils
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt:49:27 Unresolved reference: TaskDbHelper
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt:49:42 Unresolved reference: TaskDbHelper
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt:369:13 Unresolved reference: IntentUtils
e: file:///D:/Pub/hosted/pub.flutter-io.cn/flutter_downloader-1.11.5/android/src/main/kotlin/vn/hunghd/flutterdownloader/TaskDao.kt:8:37 Unresolved reference: TaskDbHelper

环境:
[✓] Flutter (Channel stable, 3.16.3, on Microsoft Windows [版本 10.0.22621.2715], locale zh-CN)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.11)
[✓] Android Studio (version 2023.1)
[✓] Connected device (4 available)
[✓] Network resources

版本:1.8.0

Management of downloaded files

It would be very helpful to add API for manage downloaded files, including:

  1. Get a list of all downloaded files
  2. Keep file access time (most recent time of getPhysicalFilePathForUrl calling)

These can be very helpful for user to manage storage usage.

remove 后,调用 getTaskForUrl 还能获取到 task

调用完 ALDownloader.remove(url); 后调用 var all = await ALDownloader.tasks;var task = await ALDownloader.getTaskForUrl(url); 还能获取到这个链接的 task,是这样设计的吗?

可复现代码

void main() {
  ALDownloader.initialize();
  ALDownloader.configurePrint(true, frequentEnabled: false);
  return runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Material App Bar'),
        ),
        body: ElevatedButton(
            onPressed: () {
              loadTest();
            },
            child: const Text("下载测试")),
      ),
    );
  }

  Future<void> loadTest() async {
    var url = "https://github.com/jackleemeta/al_downloader_flutter.git";
    var directory = await getApplicationDocumentsDirectory();
    ALDownloader.download(url,
        directoryPath: "${directory.path}/data",
        fileName: "fileName",
        handlerInterface: ALDownloaderHandlerInterface(
            progressHandler: (progress) {},
            succeededHandler: () async {
              // 下载成功
              ALDownloader.remove(url);
              var all = await ALDownloader.tasks;
              var task = await ALDownloader.getTaskForUrl(url);
              print("------------- 任务数量 ${all.length}");
              print("------------- 任务链接 ${task?.url}");
            },
            failedHandler: () {},
            pausedHandler: () {}));
  }
}

我发现 FlutterDownloader 里其实已经移除了

static Future<void> _removeTask(ALDownloaderInnerTask task) async {
    final taskId = task.taskId;

    _addOrUpdateTaskForUrl(
        task.url, taskId, ALDownloaderInnerStatus.deprecated, 0, null, null, task.waitingPhase);

    task.willParameters = null;
    task.headers = null;
    task.redownloadIfNeeded = false;
    task.isMayRedownloadAboutPause = false;
    // 在这里 FlutterDownloader.loadTasks(); 有任务
    var all = await FlutterDownloader.loadTasks();
    if (taskId.length > 0)
      await FlutterDownloader.remove(taskId: taskId, shouldDeleteContent: true);
      // 在这里 FlutterDownloader.loadTasks(); 没任务,成功移除了。
    var all2 = await FlutterDownloader.loadTasks();
  }

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.