string static method

String string(
  1. dynamic v, {
  2. String def = "",
})

Safely converts a dynamic value v to String.

Returns def if the value is null. If the value is not a String, it calls .toString().

Example:

JsonCare.string(123); // "123"
JsonCare.string(null, def: "N/A"); // "N/A"

Implementation

static String string(dynamic v, {String def = ""}) {
  if (v == null) return def;
  if (v is String) return v;
  _logMismatchedType("String", v);
  return v.toString();
}