skip to Main Content

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();
    }
  }

2

Answers


  1. Chosen as BEST ANSWER

    You must change the following line:

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

    To this:

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

  2. try this.

    final ResponseModel responseModel = ResponseModel.fromResponse(response.body);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search