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)+'%');
}
}
原文地址:https://blog.csdn.net/qq_40745143/article/details/143742129
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!