parseString function

String? parseString(
  1. Object? v, [
  2. String? def
])

Parses v as String.

def Default value if v is invalid.

Implementation

String? parseString(Object? v, [String? def]) {
  if (v == null) return def;

  if (v is String) return v;

  var s = v.toString().trim();

  if (s.isEmpty) return def;

  return s;
}