Table of contents
1.
Introduction
2.
What is Flutter Downloader?
2.1.
Key Features
2.2.
Why Flutter Downloader?
2.3.
Implementing Flutter Downloader
3.
Frequently Asked Questions
3.1.
Is Flutter Downloader compatible with both Android and iOS?
3.2.
Can I cancel a download task?
3.3.
How do I specify where the downloaded files are stored?
4.
Conclusion
Last Updated: Feb 5, 2025

How to Use Flutter Downloader

Author Ravi Khorwal
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Downloading files is a common task in modern apps. Whether it's an image, a PDF document, or a video file, the ability to download and store data is critical. While Flutter offers basic file handling capabilities, when it comes to downloading, Flutter Downloader takes it to the next level. If you're scratching your head wondering what Flutter Downloader is and how to use it, you're in luck! 

How to Use Flutter Downloader

This article will guide you through the fundamentals of Flutter Downloader, its key features, and a step-by-step tutorial to get you up and running.

What is Flutter Downloader?

Flutter Downloader is a Flutter plugin that allows you to download files from the internet and save them to local storage. It supports both Android and iOS platforms and comes packed with features like background downloading and download resumption.

Key Features

Background Downloading: Continue downloading even when the app is in the background.

Pause and Resume: Pause downloads and resume them later.

Multiple Downloads: Download multiple files simultaneously.

Notification: Receive updates on the download progress.

Why Flutter Downloader?

You may wonder why you should opt for Flutter Downloader when Flutter itself offers file handling. The answer lies in the additional features that this plugin provides, including but not limited to, background downloading and pause-resume capabilities.

Getting Started with Flutter Downloader

To utilize the power of Flutter Downloader, you first need to install it. Here’s how to get started:

Installation

Add the Flutter Downloader package to your pubspec.yaml file:

dependencies:
  flutter:
    sdk: flutter
  flutter_downloader: ^1.5.2

Run flutter packages get to install the new dependency.

Permissions

Don't forget to add the necessary permissions to your Android and iOS projects:

For Android, add the following to your AndroidManifest.xml:

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

For iOS, add the following to your Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

Implementing Flutter Downloader

With the setup complete, let's dive into some code!

Initialize Flutter Downloader

First, initialize Flutter Downloader in the main.dart file:
import 'package:flutter_downloader/flutter_downloader.dart';

void main() {
  FlutterDownloader.initialize();
  runApp(MyApp());
}

Download a File

To download a file, use the enqueue method:

final taskId = await FlutterDownloader.enqueue(
  url: 'https://example.com/file.zip',
  savedDir: 'the_path_to_save',
  fileName: 'file.zip',
  showNotification: true,
);

Monitor Download Progress

You can monitor the download progress by listening to the Flutter Downloader events:

FlutterDownloader.registerCallback((id, status, progress) {
  print('Download task ($id) is in status ($status) and process ($progress)');
});

Frequently Asked Questions

Is Flutter Downloader compatible with both Android and iOS?

Yes, Flutter Downloader works on both Android and iOS platforms.

Can I cancel a download task?

Absolutely, you can cancel a download task using the FlutterDownloader.cancel(taskId: taskId) method.

How do I specify where the downloaded files are stored?

You can specify the storage location using the savedDir parameter in the enqueue method.

Conclusion

Flutter Downloader is a powerful plugin that adds robust file downloading capabilities to your Flutter apps. With features like background downloading, pausing and resuming downloads, and real-time progress updates, it offers a comprehensive solution for any app that requires file downloading. So the next time you're grappling with how to handle file downloads in Flutter, remember that Flutter Downloader has got your back. Happy coding!

For more information, refer to our Guided Path on Coding Ninjas Studio to upskill yourself in PythonData Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more! 

Head over to our practice platform, CodeStudio, to practice top problems, attempt mock tests, read interview experiences and interview bundles, follow guided paths for placement preparations, and much more!

Live masterclass