simple_downloader

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

simple downloader

simple_downloader #
A flutter package for handle downloading file using http in more simple & easy.
Getting Started #
In your flutter project add the dependency in your pubspec.yaml:
dependencies:
...
simple_downloader: ^0.0.3
copied to clipboard
Usage #
importing package #
import 'package:simple_downloader/simple_downloader.dart';
copied to clipboard
Initialize #
late SimpleDownloader _downloader;

double _progress = 0.0;
int _offset = 0;
int _total = 0;
DownloadStatus _status = DownloadStatus.undefined;
DownloaderTask _task = const DownloaderTask(
url:"https://images.unsplash.com/photo-1615220368123-9bb8faf4221b?ixlib=rb-1.2.1&dl=vadim-kaipov-f6jkAE1ZWuY-unsplash.jpg&q=80&fm=jpg&crop=entropy&cs=tinysrgb",
fileName: "images_downloaded.jpg",
bufferSize:
1024, // if bufferSize value not set, default value is 64 ( 64 Kb )
);

@override
void initState() {
super.initState();
init();
}

Future<void> init() async {
final pathFile = (await path.getExternalStorageDirectory())!.path;
if (!mounted) return;

_task = _task.copyWith(
downloadPath: pathFile,
);

_downloader = SimpleDownloader.init(task: _task);

_downloader.callback.addListener(() {
setState(() {
_progress = _downloader.callback.progress;
_status = _downloader.callback.status;
_total = _downloader.callback.total;
_offset = _downloader.callback.offset;
});
});
}

copied to clipboard
Dispose #
@override
void dispose() {
_downloader.dispose();
super.dispose();
}

copied to clipboard
To start downloader #
_downloader.download();
copied to clipboard
To pause downloader #
_downloader.pause();
copied to clipboard
To resume downloader #
_downloader.resume();
copied to clipboard
To cancel downloader #
_downloader.cancel();
copied to clipboard
To retry downloader #
_downloader.retry();
copied to clipboard
To restart downloader #
_downloader.restart();
copied to clipboard
To open downloaded file if complete ( Support android only ) #
_downloader.open().then(
(isSuccess) {
if (!isSuccess!) {
print(context, "Failed to open downloaded file.");
}
},
);
copied to clipboard
Android Integration #
In order to handle click action to open the downloaded file, you need to add some additional configurations.
Add the following to AndroidManifest.xml:
<application>
...
<provider
android:name="adry.app.simple_downloader.FileProvider"
android:authorities="${applicationId}.simple_downloader.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_path"/>
</provider>
<application>
copied to clipboard
In order to open APK files, your application needs REQUEST_INSTALL_PACKAGES permission.
Add the following to AndroidManifest.xml:
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
copied to clipboard
Note #
This plugin is not support for downloading file from google drive.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.

Related Products

More From This Creator