isEq<T> function

Validator isEq<T>(
  1. T expected
)

Checks whether the given value is equal to the expected value of type T

Even though this function accepts any Type, note that it will not work with Collections. For that usecase prefer using isDeepEqual instead.

Implementation

Validator isEq<T>(T expected) {
  return and(
    isType<T>(),
    (value) => Result(
      isValid: value == expected,
      // json.encode is here to format the value correctly, so we know if for example 10 is a number (10) or a string ("10").
      expected: 'equal to ${pretifyValue(expected)}',
      value: value,
    ),
  );
}