【问题标题】:Receiving from a .fold "emit was called after an event handler completed normally."从 .fold 接收“在事件处理程序正常完成后调用了 emit。”
【发布时间】:2022-12-15 12:12:24
【问题描述】:

因为我在 cmets 中找到了隐藏我的问题的解决方案,所以我把它放在一个更显眼的地方:

问题:在 Dart .fold 方法中等待某个函数后,我收到了上述错误。

_failureOrProperty.fold(
          (failure) async => emit(state.copyWith(
              status: () => DataTransStatus.failure,
          (data) async {
            final List<int>? taskTypeCnts = await getTasksCount(_calledId!);
//            final List<int>? taskTypeCnts=[1,1];
            emit(state.copyWith(
                status: () => DataTransStatus.success,
                noOfMandatory: () => taskTypeCnts?[0],
                noOfOptional: () => taskTypeCnts?[1]
            ));
          }

使用评论中的行,一切正常,等待getTasksCount() 没有。

【问题讨论】:

    标签: flutter async-await flutter-bloc dartz


    【解决方案1】:

    简单的解决方案是将第一行修改为await

    await _failureOrProperty.fold(. // PLACING await IN FRONT OF THE .fold
              (failure) async => emit(state.copyWith(
                  status: () => DataTransStatus.failure,
              (data) async {
                final List<int>? taskTypeCnts = await getTasksCount(_calledId!);
    //            final List<int>? taskTypeCnts=[1,1];
                emit(state.copyWith(
                    status: () => DataTransStatus.success,
                    noOfMandatory: () => taskTypeCnts?[0],
                    noOfOptional: () => taskTypeCnts?[1]
                ));
              }
    

    【讨论】:

      猜你喜欢
      • 2022-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多