【问题标题】:A value of type 'StreamSink<dynamic>' can't be returned from the function 'assessmentSink'无法从函数“assessmentSink”返回“StreamSink<dynamic>”类型的值
【发布时间】:2022-01-17 06:56:58
【问题描述】:
class AssessmentBloc {


  late AssessmentRepository _genRepository;

  late StreamController assessmentController;
  late StreamController submitAssessmentController;


  StreamSink<ApiResponse<AssessmentModel>> get assessmentSink => assessmentController.sink;
  StreamSink<ApiResponse<AssessmentResult>> get submitSink => submitAssessmentController.sink;


  AssessmentBloc() {
    assessmentController = StreamController<ApiResponse<AssessmentModel>>();
    submitAssessmentController = StreamController<ApiResponse<AssessmentResult>>();

    _genRepository = AssessmentRepository();
  }




  dispose() {
    assessmentController?.close();
    submitAssessmentController?.close();
  }
}



 class ApiResponse<T> {
  States state;

  T? data;

  String? message;
  bool? status;

  ApiResponse.loading(this.message) : state = States.LOADING;

  ApiResponse.completed(this.data) : state = States.COMPLETED;
  //ApiResponse.completedWithMsg(this.message) : state = States.COMPLETED;
  ApiResponse.completedWithMsg({this.status, this.message}) : state = States.COMPLETED_WITH_MSG;

  ApiResponse.error(this.message) : state = States.ERROR;
  ApiResponse.reset() : state = States.RESET;

  @override
  String toString() {
    return "States : $state \n Message : $message \n Data : $data";
  }
}

枚举状态 { LOADING、COMPLETED、COMPLETED_WITH_MSG、ERROR、RESET}

刚刚将代码迁移到 null-safety dart 版本 2.12,此行出现错误。以前的版本 2.7.0 运行良好。如果有人能在这方面帮助我,我将不胜感激。

A value of type 'StreamSink<dynamic>' can't be returned from the function 'assessmentSink' because it has a return type of 'StreamSink<ApiResponse<AssessmentModel>>'.

【问题讨论】:

  • 你能把你的code-sn-p也包括进来吗?
  • 你好先生.. 我的代码 sn-p 更新了。如果你能帮助我,不胜感激
  • 你可以试试 typecast 吗,比如variable as dataType

标签: flutter dart dart-null-safety null-safety


【解决方案1】:

尝试将流控制器的类型定义为:

late StreamController<ApiResponse<AssessmentModel>> submitAssessmentController;

【讨论】:

    猜你喜欢
    • 2021-07-11
    • 1970-01-01
    • 2022-01-26
    • 2021-01-25
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    相关资源
    最近更新 更多