stringifyBody static method

String stringifyBody(
  1. dynamic body
)

Pretty-prints body for the editor when possible.

Implementation

static String stringifyBody(dynamic body) {
  if (body == null) return '';
  if (body is String) {
    final trimmed = body.trim();
    if (trimmed.isEmpty) return '';
    try {
      return const JsonEncoder.withIndent('  ').convert(jsonDecode(trimmed));
    } catch (_) {
      return body;
    }
  }
  try {
    return const JsonEncoder.withIndent('  ').convert(body);
  } catch (_) {
    return body.toString();
  }
}