How to Save Files from URL to Download Folder in Flutter

In this example, we are going to show you how to download any kind of file and save it to the Download folder using Flutter. You can have a progress indicator to show the progress of downloading using this example.

First, you need to add downloads_path_provider_28permission_handlerdio Flutter packages in your project by adding the following lines in pubspect.yaml file.

    sdk: flutter
  downloads_path_provider_28: ^0.1.2
  permission_handler: ^8.3.0
  dio: ^4.0.4

Add Read and Write Permission on AndroidManifest.xml file:

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

Also, Add this attribute on the <application> tag in AndroidManifest.xml file:


import 'package:dio/dio.dart';
import 'package:downloads_path_provider_28/downloads_path_provider_28.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

void main() {
  runApp( MaterialApp(
       home: Home()

class Home extends  StatefulWidget {
  State<Home> createState() => _HomeState();

class _HomeState extends State<Home> {

  String fileurl = "";
  //you can save other file formats too.
  Widget build(BuildContext context) {
    return Scaffold(
         resizeToAvoidBottomInset: false,
         appBar: AppBar(
            title: Text("Download File from URL"),
            backgroundColor: Colors.deepPurpleAccent,
          body: Container(
             margin: EdgeInsets.only(top:50),
             child: Column(
                 children: [
                      Text("File URL: $fileurl"),
                         onPressed: () async {
                            Map<Permission, PermissionStatus> statuses = await [
                                //add more permission to request here.

                                var dir = await DownloadsPathProvider.downloadsDirectory;
                                if(dir != null){
                                      String savename = "file.pdf";
                                      String savePath = dir.path + "/$savename";
                                      //output:  /storage/emulated/0/Download/banner.png

                                      try {
                                          await Dio().download(
                                              onReceiveProgress: (received, total) {
                                                  if (total != -1) {
                                                      print((received / total * 100).toStringAsFixed(0) + "%");
                                                      //you can build progressbar feature too
                                           print("File is saved to download folder.");  
                                     } on DioError catch (e) {
                               print("No permission to read and write.");

                         child: Text("Download File."),


Widget Output:

File Info Output:

In this way, you can download any kind of file from Network URL and save it to Download folder in the Flutter app.

No any Comments on this Article

Please Wait...