fromList method

Converter fromList(
  1. int index
)

Extracts a value from a List using the specified index.

If the current value is a JSON string representing a list, it is automatically decoded. If the index is out of bounds or the value is not a list, the result wraps null.

Implementation

Converter fromList(int index) {
  final v = _value;
  if (v is List) {
    return Converter(
      index >= 0 && index < v.length ? v[index] : null,
      defaultValue: _defaultValue,
      customConverter: _customConverter,
    );
  }
  if (v is String) {
    final decoded = v.tryDecode();
    if (decoded is List) {
      return Converter(
        index >= 0 && index < decoded.length ? decoded[index] : null,
        defaultValue: _defaultValue,
        customConverter: _customConverter,
      );
    }
  }
  return Converter(
    null,
    defaultValue: _defaultValue,
    customConverter: _customConverter,
  );
}