In this example, we are going to show you how to get the "Download" folder path from Local Storage in the Flutter app. You can further use the Download folder path to save files.
First, you need to add downloads_path_provider_28 Flutter package in your project by adding the following lines in pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
downloads_path_provider_28: ^0.1.2
Add Read Permission on AndroidManifest.xml file:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Remember, this will only get a storage path. If you want to write files as well, you need to ask permission from the app level. See the example here:
Read This Also: How to Save Files from URL to Download Folder in Flutter
import 'package:downloads_path_provider_28/downloads_path_provider_28.dart';
var dir = await DownloadsPathProvider.downloadsDirectory;
if(dir != null){
String downloadfolder = dir.path;
print(downloadfolder); //output: /storage/emulated/0/Download
}else{
print("No download folder found.");
}
import 'package:downloads_path_provider_28/downloads_path_provider_28.dart';
import 'package:flutter/material.dart';
void main() {
runApp( MaterialApp(
home: Home()
));
}
class Home extends StatefulWidget {
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
String downloadfolder = "";
@override
void initState() {
Future.delayed(Duration.zero, () async {
var dir = await DownloadsPathProvider.downloadsDirectory;
if(dir != null){
downloadfolder = dir.path;
print(downloadfolder); //output: /storage/emulated/0/Download
setState(() {
//refresh UI
});
}else{
print("No download folder found.");
}
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: Text("Get Download Folder Path"),
backgroundColor: Colors.deepPurpleAccent,
),
body: Container(
margin: EdgeInsets.only(top:50),
alignment: Alignment.topCenter,
child: Column(
children: [
Text(downloadfolder, style: TextStyle(fontSize: 18)),
],
),
)
);
}
}
In this way, you can get the "Download" folder path from Local storage in Flutter App.
Please Wait...
No any Comments on this Article