flutter_downloader 1.0.6

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 97

Flutter Downloader #

pub package

A plugin for creating and managing download tasks. Supports iOS and Android.

This plugin is based on WorkManager in Android and NSURLSessionDownloadTask in iOS to run download task in background mode.

iOS integration #

  • Open ios project (file Runner.xcworkspace) in Xcode.

  • Enable background mode.

  • Add sqlite library.

Note: If you want to download file with HTTP request, you need to disable Apple Transport Security (ATS) feature.

  • Disable ATS for a specific domain only: (add following codes to the end of your Info.plist file)
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>www.yourserver.com</key>
    <dict>
      <!-- add this key to enable subdomains such as sub.yourserver.com -->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!-- add this key to allow standard HTTP requests, thus negating the ATS -->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!-- add this key to specify the minimum TLS version to accept -->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>
  • Completely disable ATS: (add following codes to the end of your Info.plist file)
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key><true/>
</dict>

Android integration #

In order to handle click action on notification to open the downloaded file on Android, you need to add some additional configurations:

  • add the following codes to your AndroidManifest.xml (inside application tag):
<provider
    android:name="vn.hunghd.flutterdownloader.DownloadedFileProvider"
    android:authorities="${applicationId}.flutter_downloader.provider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/provider_paths"/>
</provider>
  • you have to save your downloaded files in external storage (where the other applications have permission to read your files)

Note: The downloaded files are only able to be opened if your device has at least an application that can read these file types (mp3, pdf, etc)

Usage #

import 'package:flutter_downloader/flutter_downloader.dart';

Initialize plugin: #

FlutterDownloader.initialize(
  maxConcurrentTasks: 3, // config the maximum number of tasks running at a moment
  messages: {....} // localize messages for Android notification
);

Create new download task: #

final taskId = await FlutterDownloader.enqueue(
  url: 'your download link',
  savedDir: 'the path of directory where you want to save downloaded files',
  showNotification: true, // show download progress in status bar (for Android)
  openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);

Update download progress: #

FlutterDownloader.registerCallback((id, status, progress) {
  // code to update your UI
});

Load all tasks: #

final tasks = await FlutterDownloader.loadTasks();

Load tasks with conditions: #

final tasks = await FlutterDownloader.loadTasksWithRawQuery(query: query);
  • Note: In order to parse data into DownloadTask object successfully, you should load data with all fields from DB (in the other word, use: SELECT * ). For example:
SELECT * FROM task WHERE status=3
  • Note: the following is the schema of task table where this plugin stores tasks information
CREATE TABLE `task` (
	`id`	INTEGER PRIMARY KEY AUTOINCREMENT,
	`task_id`	VARCHAR ( 256 ),
	`url`	TEXT,
	`status`	INTEGER DEFAULT 0,
	`progress`	INTEGER DEFAULT 0,
	`file_name`	TEXT,
	`saved_dir`	TEXT,
	`resumable`	TINYINT DEFAULT 0,
	`headers`	TEXT,
	`show_notification`	TINYINT DEFAULT 0,
	`open_file_from_notification`	TINYINT DEFAULT 0,
	`time_created`	INTEGER DEFAULT 0
);

Cancel a task: #

FlutterDownloader.cancel(taskId: taskId);

Cancel all tasks: #

FlutterDownloader.cancelAll();

Pause a task: #

FlutterDownloader.pause(taskId: taskId);

Resume a task: #

FlutterDownloader.resume(taskId: taskId);
  • Note: resume() will return a new taskId corresponding to a new background task that is created to continue the download process. You should replace the original taskId (that is marked as paused status) by this new taskId to continue tracking the download progress.

Retry a failed task: #

FlutterDownloader.retry(taskId: taskId);
  • Note: retry() will return a new taskId (like resume())

Open and preview a downloaded file: #

FlutterDownloader.open(taskId: taskId);
  • Note: in Android, you can only open a downloaded file if it is placed in the external storage and there's at least one application that can read that file type on your device.

Bugs/Requests #

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on Github. Pull request are also welcome.

1.0.6 - 28.10.2018 #

  • fix bug related to filename

1.0.5 - 22.10.2018 #

  • Android: re-config dependencies

1.0.4 - 20.10.2018 #

  • Android: upgrade WorkManager to v1.0.0-alpha10

1.0.3 - 29.09.2018 #

  • Android: upgrade compile sdk version to 28

1.0.2 - 20.09.2018 #

  • Fixed Flutter Community badge.

1.0.1 - 20.09.2018 #

1.0.0 - 09.09.2018 #

  • NEW features: initialize, loadTasksWithRawQuery, pause, resume, retry, open
  • IMPORTANT: the plugin must be initialized by initialize() at first
  • BREAKING CHANGE: clickToOpenDownloadedFile now renames to openFileFromNotification (to prevent confusing from open feature). Static property maximumConcurrentTask has been removed, this configuration now moves into initialize() method.
  • full support SQLite on both Android and iOS side, the plugin now itself manages its states persistently and exposes loadTasksWithRawQuery api that helps developers to load tasks from SQLite database with customized conditions
  • support localizing Android notification messages with messages parameter of initialize() method
  • full support opening and previewing downloaded file with open() method
  • (iOS integration) no need to override application:handleEventsForBackgroundURLSession:completionHandler: manually anymore, the plugin now itself takes responsibility for handling it

0.1.1 - 29.08.2018 #

  • fix bugs: SQLite leak
  • new feature: support configuration of the maximum of concurrent download tasks
  • upgrade WorkManager to v1.0.0-alpha08

0.1.0 - 12.08.2018 #

  • add: handle click on notification to open downloaded file (for Android)

0.0.9 - 10.08.2018 #

  • re-config to support Dart2

0.0.8 - 10.08.2018 #

  • upgrade WorkManager to v1.0.0-alpha06
  • fix bug: disable sound on notifications

0.0.7 - 28.06.2018 #

  • upgrade WorkManager to v1.0.0-alpha04

0.0.6 - 28.06.2018 #

  • upgrade WorkManager to v1.0.0-alpha03
  • change default value of showNotification to true (it makes sense on Android 8.0 and above, it helps our tasks not to be killed by system when the app goes to background)

0.0.5 - 22.06.2018 #

  • update metadata

0.0.4 - 15.06.2018 #

  • fix bug: Worker finished with FAILURE on Android API 26 and above

0.0.3 - 11.06.2018 #

  • support HTTP headers

0.0.2 - 08.06.2018 #

  • correct README document

0.0.1 - 07.06.2018 #

  • initial release.

example/README.md

flutter_downloader_example #

Demonstrates how to use the flutter_downloader plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_downloader: ^1.0.6

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_downloader/flutter_downloader.dart';
  
Version Uploaded Documentation Archive
1.1.7 Mar 24, 2019 Go to the documentation of flutter_downloader 1.1.7 Download flutter_downloader 1.1.7 archive
1.1.6 Feb 9, 2019 Go to the documentation of flutter_downloader 1.1.6 Download flutter_downloader 1.1.6 archive
1.1.5 Jan 27, 2019 Go to the documentation of flutter_downloader 1.1.5 Download flutter_downloader 1.1.5 archive
1.1.4 Jan 6, 2019 Go to the documentation of flutter_downloader 1.1.4 Download flutter_downloader 1.1.4 archive
1.1.3 Nov 18, 2018 Go to the documentation of flutter_downloader 1.1.3 Download flutter_downloader 1.1.3 archive
1.1.2 Nov 14, 2018 Go to the documentation of flutter_downloader 1.1.2 Download flutter_downloader 1.1.2 archive
1.1.1 Nov 12, 2018 Go to the documentation of flutter_downloader 1.1.1 Download flutter_downloader 1.1.1 archive
1.1.0 Nov 12, 2018 Go to the documentation of flutter_downloader 1.1.0 Download flutter_downloader 1.1.0 archive
1.0.6 Oct 28, 2018 Go to the documentation of flutter_downloader 1.0.6 Download flutter_downloader 1.0.6 archive
1.0.5 Oct 22, 2018 Go to the documentation of flutter_downloader 1.0.5 Download flutter_downloader 1.0.5 archive

All 26 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
94
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
97
Learn more about scoring.

We analyzed this package on May 8, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.0
  • pana: 0.12.15
  • Flutter: 1.5.8

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-0.33 points)

43 out of 44 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/flutter_downloader.dart.

Run flutter format to format lib/flutter_downloader.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test