首页 > 解决方案 > 在 ui 中访问进度表单上传

问题描述

我正在使用 dio 包(在示例中抽象出来)上传视频。onSendProgresspost 方法有一个效果很好的回调(我可以在打印语句中看到它)。我的问题是向 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 ..(如果需要,我可以添加其他状态)

标签: flutter

解决方案


推荐阅读