Flutter 上传进度的增量进度
我从回调接收进度并添加如下事件: 数据/集团Flutter 上传进度的增量进度,flutter,Flutter,我从回调接收进度并添加如下事件: 数据/集团 onSendProgress: (int sent, int total) { var progress = sent / total; this.add(ProgressUpdate(progress)); }, 对于我的ui中的动画,进度太快 用户界面 想知道以10为间隔增加响应的最佳方法是什么?假设您可以访问当前值(如ValueStream
onSendProgress: (int sent, int total) {
var progress = sent / total;
this.add(ProgressUpdate(progress));
},
对于我的ui中的动画,进度太快
用户界面
想知道以10为间隔增加响应的最佳方法是什么?假设您可以访问当前值(如
ValueStream
中的rxdart
),您可以执行以下操作:
void main(){
var currentIncrement=0;
对于(var i=0;i currentIncrement){
当前增量=增量;
打印('Progress updated!${currentIncrement*10}%');
}
}
}
印刷品:
Progress updated! 10%
Progress updated! 20%
Progress updated! 30%
Progress updated! 40%
Progress updated! 50%
Progress updated! 60%
Progress updated! 70%
Progress updated! 80%
Progress updated! 90%
Progress updated! 100%
在您的情况下,它看起来与此类似(我没有编译它,因此需要一些调整):
onSendProgress:(已发送,总计){
最终进度=(已发送/总计*100)~/10;
如果(进度>当前值){
添加(ProgressUpdate(progress));
}
}
细分:
-表示进度的分数,例如0.32表示32%sent/total
-实际百分比,例如32%已发送/总计*100
此函数将一个数字除以任何分数,因此如果执行~/10
操作,将得到32~/10
3
进度的解释
Progress updated! 10%
Progress updated! 20%
Progress updated! 30%
Progress updated! 40%
Progress updated! 50%
Progress updated! 60%
Progress updated! 70%
Progress updated! 80%
Progress updated! 90%
Progress updated! 100%