This is My code snippet instead of mypdf.pdf i want to get filename from the url like in android app development,since I'm new in flutter i have no idea can anyone help me
Future<void> downloadPDF() async {
Dio dio = Dio();
try {
var dir = await getApplicationDocumentsDirectory();
await dio.download(pdfurl, "${dir.path}/mypdf.pdf",
onProgress: (rec, total) {
setState(() {
downloading = true;
progressString = ((rec / total) * 100).toStringAsFixed(0) + "%";
});
});
} catch (e) {
print(e);
}
setState(() {
downloading = false;
progressString = "Completed";
});
print("Download completed");
}
did you try it ?
File file = new File("/dir1/dir2/file.ext");
String basename = basename(file.path);
# file.ext
for more details https://flutter.dev/docs/cookbook/persistence/reading-writing-files