-1

这是我的代码片段而不是 mypdf.pdf 我想从 url 获取文件名,就像在 android 应用程序开发中一样,因为我是 Flutter 的新手,我不知道任何人都可以帮助我

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");

}

4

2 回答 2

0

你试过了吗?

File file = new File("/dir1/dir2/file.ext");
String basename = basename(file.path);
# file.ext

有关更多详细信息https://flutter.dev/docs/cookbook/persistence/reading-writing-files

于 2020-04-01T07:17:27.623 回答
0
 final url = "http://africau.edu/images/default/sample.pdf";
 final filename = url.substring(url.lastIndexOf("") + 1);
于 2021-04-28T11:34:31.793 回答