toStringValue static method

String? toStringValue(
  1. Object? value, [
  2. String? def
])

Returns value as a String.

Implementation

static String? toStringValue(Object? value, [String? def]) {
  if (value == null) return def;

  String valueStr;

  if (value is String) {
    valueStr = value;
  } else if (value is List) {
    valueStr = value.map((e) => toStringValue(e)).join(',');
  } else if (value is Map) {
    valueStr = value.entries
        .expand((e) => ['${e.key}:${toStringValue(e.value)}'])
        .toList()
        .join(';');
  } else if (value is Iterable) {
    valueStr = value.map(toStringValue).join(',');
  } else if (value is Pair) {
    valueStr = value.join(',');
  } else if (value is MapEntry) {
    valueStr = '${value.key},${value.value}';
  } else {
    valueStr = '$value';
  }

  return valueStr;
}