convertResponse<BodyType, InnerType> method

  1. @override
Response<BodyType> convertResponse<BodyType, InnerType>(
  1. Response response
)

Converts the received Response to a Response which has a body of the type BodyType.

BodyType is the expected type of the resulting Response's body (e.g., String or CustomObject).

If BodyType is a List or a BuiltList, InnerType is the type of the generic parameter (e.g., convertResponse<List<CustomObject>, CustomObject>(response) ).

Implementation

@override
Response<BodyType> convertResponse<BodyType, InnerType>(Response response) {
  // BodyType: Type of model we want are respinse to be converted.

  // InnerType is type of model we want to convert our response from api when we are getting List of Map<String,dynamic>,
  // so in this case our BodyType will be List

  return response.copyWith(
      body: decode<BodyType, InnerType>(json.decode(response.body)));
}