onResponse method

  1. @override
void onResponse(
  1. Response response,
  2. ResponseInterceptorHandler handler
)

Called when the response is about to be resolved.

Implementation

@override
void onResponse(Response response, ResponseInterceptorHandler handler) async {
  String responseStr = "\n==================== Response ====================\n"
      "- URL: ${response.requestOptions.uri}\n";
  responseStr += "- HEADER:\n{";
  response.headers.forEach((key, list) => responseStr += "\n  " "\"$key\" : \"$list\",");
  responseStr += "\n}\n";
  responseStr += "- STATUS: ${response.statusCode}\n";

  if (response.data != null) {
    responseStr += "- BODY:\n${_parseResponse(response)}\n";
  }
  handler.next(response);
}