Reputation: 103
Future<void> downloadFile() async{
Dio dio = Dio() ;
try{
var dir = await getApplicationDocumentsDirectory();
print('DIR is :${dir}');
await dio.download(pdfUrl, "${dir.path}/sample.pdf",onReceiveProgress: (rec,total){
print('rec:${rec},total:${total}');
setState(() {
downloading=true ;
progressString =((rec / total) * 100).toStringAsFixed(0) + "%" ;
});
});
}catch(e){
print(e);
}
setState(() {
downloading = false;
progressString = "Completed";
});
print("Download completed");
}
I want to store my downloaded pdf for offline use, how can I implement it? How can I save in downloads/(sample.pdf) local folder and can retrieve files whenever offline?
Upvotes: 2
Views: 1426
Reputation: 803
On iOS, this uses the NSDocumentDirectory API. Consider using getApplicationSupportDirectory instead if the data is not user-generated.
On Android, this uses the getDataDirectory API on the context. Consider using getExternalStorageDirectory instead if data is intended to be visible to the user.
So I don't know the App size means? if u download a file to app's dir , this will obvious increase app cache or some other size , but will not increate apk size.
Upvotes: 1