我在db中有一个文件,用户可以通过flutter_downloader
包下载它,它的工作很好。现在我如何显示消息给用户后,文件下载完成?
主文件:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize(
debug: true // optional: set false to disable printing logs to console
);
runApp(const MyApp());
}
我想在下载文件时显示消息
你可以使用flutter_file_downloader库它有你想要的回调,它也有一个进度监听器
使用示例FileDownloader.downloadFile(
url: "https://tinypng.com/images/social/website.jpg",
name: "PANDA",
onProgress: (String? fileName, double progress) {
print('FILE fileName HAS PROGRESS $progress');
},
onDownloadCompleted: (path) {
final File file = File(path);
//This will be the path of the downloaded file
});
或者您可以在完成后使用
获取下载的文件final File? file = await FileDownloader.downloadFile(
url: "https://tinypng.com/images/social/developer-api.jpg",
name: "ANOTHER PANDA.jpg");
print('FILE: ${file?.path}');
如果你发现任何问题或错误,请不要犹豫,在github问题部分打开一个错误,将很高兴帮助解决它