Search code examples
flutterdartdart-null-safetynull-safety

A value of type 'StreamSink<dynamic>' can't be returned from the function 'assessmentSink'


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";
  }
}

enum States { LOADING, COMPLETED, COMPLETED_WITH_MSG, ERROR, RESET}

enter image description here

just migrated code to null-safety dart version 2.12, error appearing on this line. previous version 2.7.0 work well. I would appreciate if any of you can help me on this.

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

Solution

  • Try defining the type of stream controller as:

    late StreamController<ApiResponse<AssessmentModel>> submitAssessmentController;