optionalString function

String? optionalString(
  1. CrossmintJsonMap map,
  2. String key
)

Returns the string at key in map if it exists and is a string, otherwise null. Empty strings are returned as-is so callers can distinguish "absent" from "explicitly empty" if needed.

Implementation

String? optionalString(CrossmintJsonMap map, String key) {
  final Object? value = map[key];
  return value is String ? value : null;
}