handle method

  1. @override
List<T> handle(
  1. dynamic value, {
  2. List<T>? defaultValue,
  3. bool skipInvalid = false,
  4. SuperConverter<T>? converter,
})
override

Implementation

@override
List<T> handle(
  value, {
  List<T>? defaultValue,
  bool skipInvalid = false,

  /// to use single time used converter
  SuperConverter<T>? converter,
}) {
  if (value == null || value == [] || value == '') {
    if (defaultValue != null) return defaultValue;
  }

  if (value is String && value.isNotEmpty) value = jsonDecode(value);

  if (value is! List) {
    value = [value];
  }

  List<T> response = [];

  for (var e in value) {
    try {
      response.add(SuperConverter.convert<T>(e, converter: converter));
    } catch (e) {
      if (skipInvalid) {
        // print(
        //   '[CustomConverter][ListConverter<$T>] '
        //   'skip invalid item ${value.toString().padRight(100).substring(0, 100)}',
        // );
      } else {
        rethrow;
      }
    }
  }

  return response;
}