场景描述:上传文件,并显示加载进度条
异常描述:进度直接从0跳到100
请求工具:dio ^ 4.0.0
进度工具:flutter_easyloading ^3.0.3
事件处理:onSendProgress(int progress, int total)(上行事件)
简单粗暴直接上代码
upload(var value) async {
return await SysAttachmentServer.upload(value.name, value.bytes,
onSendProgress: (int progress, int total) {
Future.delayed(Duration(milliseconds: 1000)).then((value) {
final currentProgress = (progress / total);
EasyLoading.showProgress(currentProgress,
status: '${(currentProgress * 100).toStringAsFixed(0)}%');
if (currentProgress >= 1) {
EasyLoading.dismiss();
}
print(
"总进度==$total===当前的进度===$progress====百分比===${(currentProgress * 100).toStringAsFixed(0)}%====$currentProgress");
});
});
}
你只需要看onSendProgress事件的处理,方案简单粗暴,直接加延时操作,即在获取上行进度的时候,稍微阻塞1000毫秒显示EasyLoading。
-------------------------end