Home > Blockchain >  The argument type 'Response' can't be assigned to the parameter type 'Response&l
The argument type 'Response' can't be assigned to the parameter type 'Response&l

Time:07-29

I am trying to write a http request to firebase with this method but I am getting an error with the response.

I am getting the following error: The argument type 'Response' can't be assigned to the parameter type 'Response'. I have put astrix's over where I am getting the error.

Future<ResponseModel> postReview(
    String title,
    String category,
    String description,
    int recordId,
  ) async {
    try {
      final response = await http.post(
        Uri.parse(url),
        body: json.encode({
          "title": title,
          "category": category,
          "description": description,
          "record_id": recordId,
        },
        )
      );
      final ResponseModel responseModel = ResponseModel.fromResponse(*response*);
      return responseModel;
    } on DioError catch (e) {
      debugPrint(e.response.toString());
      throw e.response!.data['msg'].toString();
    }
  }

CodePudding user response:

try this.

final ResponseModel responseModel = ResponseModel.fromResponse(response.body);

CodePudding user response:

you must change the following line:

final ResponseModel responseModel = ResponseModel.fromResponse(*response*);

To:

final ResponseModel responseModel = ResponseModel.fromResponse(response as Response<dynamic>);
  • Related