file_downloader 0.0.1 copy "file_downloader: ^0.0.1" to clipboard
file_downloader: ^0.0.1 copied to clipboard

A new Flutter project.

file_downloader #

you can download your file like (mp3, pdf, etc)

Installation #

Now in your Dart code, you can use.

import 'package:file_downloader/file_downloader.dart';

Permission #

Add this permission to your AndroidManifest.xml file

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

Initialize #

Add these line to your main function.

 WidgetsFlutterBinding.ensureInitialized();
  await FlutterDownloader.initialize(debug: debug);

Usage #

Add this code to your AndroidManifest.xml file after activity 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>


<!-- Begin FlutterDownloader customization -->
<!-- disable default Initializer -->
<provider
    android:name="androidx.startup.InitializationProvider"
    android:authorities="${applicationId}.androidx-startup"
    android:exported="false"
    tools:node="merge">
    <meta-data
        android:name="androidx.work.WorkManagerInitializer"
        android:value="androidx.startup"
        tools:node="remove" />
</provider>

<!-- declare customized Initializer -->
<provider
    android:name="vn.hunghd.flutterdownloader.FlutterDownloaderInitializer"
    android:authorities="${applicationId}.flutter-downloader-init"
    android:exported="false">
    <!-- changes this number to configure the maximum number of concurrent tasks -->
    <meta-data
        android:name="vn.hunghd.flutterdownloader.MAX_CONCURRENT_TASKS"
        android:value="5" />
</provider> 

Add #

Add this line to initState function.

FileDownload().registerPortData(setState);

Add this line to dispose function.

  IsolateNameServer.removePortNameMapping('downloader_send_port');

Download File #

Add this line to your download button and pass URL

FileDownload().download(context,url);

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.