Flutter : Download File/Image From URL In Flutter

Akshay Papneja
1 min readDec 21, 2020

Hello all,

Here is the shortcut to download image file from URL. For all those lazy programmers. A Flutter package makes this task simple.

Start

pubspec.yaml

image_downloader: ^0.20.1

get dependencies using,

flutter pub get

import

import 'package:image_downloader/image_downloader.dart';

Add this permission in AndroidManifest.xml

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

User this code below, where you want to download image from server.

try {
var imageId = await ImageDownloader.downloadImage(url);
if (imageId == null) {
return;
}
var path = await ImageDownloader.findPath(imageId);
} on PlatformException catch (error) {
print(error);
}

You can also set your custom path where you wanna store that file

await ImageDownloader.downloadImage(url,                        destination: AndroidDestinationType.custom(directory:'sample'));

Here you all set to download the file from the server URL, you can define you path where you want to store that file, usually downloading file from server is a common task in the era of app development. So, go grab it.

Thanks me later

For reference click on the link here.

If you like this article, just give me a clap.

Happy Coding !

--

--