listContains<T> function

Validator listContains<T>(
  1. T item
)

Validates that the List contains item

This validator also validates that the value is a List first So there's no need to add the isType<List> validator when using this validator

Implementation

Validator listContains<T>(T item) {
  return (value) {
    final isListResult = isType<List>().call(value);
    if (isListResult.isNotValid) return isListResult;

    return Result(
      isValid: (value as List).contains(item),
      expected: 'List to contain ${pretifyValue(item)}',
      value: value,
    );
  };
}