optNullableString method
Returns the value mapped by name
if it exists, coercing it if necessary, or null
if no such
mapping exists.
If remove
is true, then the mapping will be removed from the Map.
Implementation
String? optNullableString(String name, {bool remove = false}) {
// optString() returns "null" if the key exists but contains the `null` value.
// https://stackoverflow.com/questions/18226288/json-jsonobject-optstring-returns-string-null
if (isNull(name)) {
return null;
}
String s = optString(name);
String? value = (s != "") ? s : null;
if (remove) {
this?.remove(name);
}
return value;
}