Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 上传进度的增量进度_Flutter - Fatal编程技术网

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));
}
}
细分:

  • sent/total
    -表示进度的分数,例如0.32表示32%
  • 已发送/总计*100
    -实际百分比,例如32%
  • ~/10
    此函数将一个数字除以任何分数,因此如果执行
    32~/10
    操作,将得到
    3

您想以10秒为间隔(即每10秒)还是以10%的间隔(每10%的进度)更新进度?10%的间隔感谢不确定从何处获取currentValue(或它是什么)<代码>(进度>当前值)至于第一部分,我不能真正帮助您,因为这取决于您使用的库。我还添加了对
进度的解释
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%