toReadableObject static method

Object? toReadableObject(
  1. Object? val
)

Recursively converts complex objects into a human-readable format. Handles Maps, Lists, BigInt, byte arrays, etc.

Implementation

static Object? toReadableObject(Object? val) {
  if (val is Map) {
    final newMap =
        val.map((key, value) => MapEntry(key, toReadableObject(value)));
    return newMap..removeWhere((e, k) => k == null);
  }
  if (val is String || val is int) {
    return val;
  }
  if (val is BigInt) {
    return val.toString();
  }
  if (val is List<int>) {
    return BytesUtils.tryToHexString(val, prefix: '0x') ?? val;
  }
  if (val is List) {
    return val.map(toReadableObject).toList();
  }
  return val.toString();
}