fromMap method

Converter fromMap(
  1. Object? key
)

Extracts a value from a Map using the specified key.

If the current value is a JSON string representing a map, it is automatically decoded. If the key is missing or the value is not a map, the result wraps null.

Implementation

Converter fromMap(Object? key) {
  final v = _value;
  if (v is Map) {
    return Converter(
      v[key],
      defaultValue: _defaultValue,
      customConverter: _customConverter,
    );
  }
  if (v is String) {
    final decoded = v.tryDecode();
    if (decoded is Map) {
      return Converter(
        decoded[key],
        defaultValue: _defaultValue,
        customConverter: _customConverter,
      );
    }
  }
  return Converter(
    null,
    defaultValue: _defaultValue,
    customConverter: _customConverter,
  );
}