Flutter:Dio下载文件到本地

import 'dart:io'; import 'package:dio/dio.dart'; main(){ // 创建dio对象 final dio = Dio(); // 下载地址 var url = 'https://*******.org/files/1.0.0.apk'; // 手机端路径 String savePath = Directory.systemTemp.path+'/ceshi.apk'; print(savePath); downLoad(dio,url,savePath); } downLoad(Dio dio,String url,String savePath){ dio.download(url, savePath,onReceiveProgress:onReceiveProgress).then((value){ print(value); }).whenComplete((){ print('下载结束'); }).catchError((onError){ print(onError); }); } // 下载的进度 void onReceiveProgress(int count, int total) { print('文件大小:$total 当前进度:$count'); if(total != -1){ print((count / total *100).toStringAsFixed(0)+'%'); } }
上一篇:MySQL高级(一):一条查询语句是如何执行的


下一篇:uniapp 上传 base64 图片