printResponse static method

void printResponse(
  1. Response response, {
  2. String? prefix,
  3. int? lineCount,
  4. int? titleCode,
  5. int? bodyCode,
  6. int? maxBodyChar,
  7. bool showAllDataBody = false,
})

print in console with style for Response http access
code must be 0-255 (for color)
Default:
lineCount = 60
titleCode = 172
bodyCode = 178
maxBodyChar = 200
showAllDataBody: false

Implementation

static void printResponse(
  http.Response response, {
  String? prefix,
  int? lineCount,
  int? titleCode,
  int? bodyCode,
  int? maxBodyChar,
  bool showAllDataBody = false,
}) {
  String method = response.request!.method;
  String url = response.request!.url.toString();
  int statusCode = response.statusCode;
  String title = "${prefix ?? 'Response: '}$method | $url | $statusCode";
  String body = response.body;
  int newMaxBodyChar = maxBodyChar ?? 200;
  String newBody = showAllDataBody
      ? body
      : body.length > newMaxBodyChar
          ? body.substring(0, newMaxBodyChar)
          : body;
  String underLine =
      "$_limitColor\u001b[38;5;244m${'_' * (lineCount ?? 60)}$_limitColor";
  String upperLine =
      "$_limitColor\u001b[38;5;244m${'‾' * (lineCount ?? 60)}$_limitColor";
  debugPrint(underLine);
  debugPrint(
      "$_limitColor\u001b[38;5;${titleCode ?? 178}m$title$_limitColor");
  debugPrint(
      "$_limitColor\u001b[38;5;${bodyCode ?? 142}m$newBody$_limitColor");
  debugPrint(upperLine);
}