isEmptyObject<T> function

bool isEmptyObject<T>(
  1. T? o, {
  2. bool trim = false,
})

Returns true if o is empty. Checks for String, List, Map Iterable, Set or o.toString().

Implementation

bool isEmptyObject<T>(T? o, {bool trim = false}) {
  if (o == null) return true;

  if (o is String) {
    return trim ? o.trim().isEmpty : o.isEmpty;
  } else if (o is List) {
    return trim ? o.where((e) => e != null).isEmpty : o.isEmpty;
  } else if (o is Map) {
    return trim ? o.entries.where((e) => e.value != null).isEmpty : o.isEmpty;
  } else if (o is Iterable) {
    return trim ? o.where((e) => e != null).isEmpty : o.isEmpty;
  } else if (o is Set) {
    return trim ? o.where((e) => e != null).isEmpty : o.isEmpty;
  } else {
    var s = o.toString();
    return trim ? s.trim().isEmpty : s.isEmpty;
  }
}