flutter - 在 ui 中访问进度表单上传
问题描述
我正在使用 dio 包(在示例中抽象出来)上传视频。onSendProgress
post 方法有一个效果很好的回调(我可以在打印语句中看到它)。我的问题是向 ui 层显示进度数据。我正在使用flutter_bloc
. 目前我有:
if (event is RequestImage) {
yield ResponsesLoading();
try {
File file;
double progress;
await apiService.uploadVideo(
responseId: event.responseId,
file: file,
accessToken: token,
onSendProgress: (int sent, int total) {
progress = sent / total;
print('progress: $progress ($sent/$total)'); //need to pass progress to ui
});
}
yield (Success());
}
} catch (e) {
yield ResponsesFailure(e.toString());
print(e.toString());
print(e.stackTrace.toString());
}
}
由于进度是 api 调用的一部分,我不确定如何将其发送到 ui ..(如果需要,我可以添加其他状态)
解决方案
推荐阅读
- nginx - 如何在 Kubernetes 中为 HashiCorp Vault UI 设置入口
- javascript - 无法通过 Rosbridge 订阅里程计 ROS 消息
- php - 按类别分类的 WordPress 相关内容为自定义帖子类型中的每个帖子产生相同的结果
- visual-studio-code - 如何在离线网络中安装 VSCode 帮助文件
- azure-devops - 在 Azure Devops 上附加到 PATH?
- javascript - Push javascript array objects from mysql query
- gnuplot - 如何根据星期几在轴上标记抽动
- r - R:在 XY 网格中查找缺失的组合
- angular - ExpressionChangedAfterItHasBeenCheckedError Angular *ngIf 指令导致错误
- android - GStreamer 管道正在播放,但没有填充回调(仅在 Android 上发生,在 Windows 和 Linux 上有效)