Skip to content

Commit 8b235d1

Browse files
remove the verb 'is' from generic validators
1 parent 38084a8 commit 8b235d1

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

example/lib/forms_with_validate_granularlly.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class _BodyState extends State<_Body> {
180180
child: Text('Invalid option 2'),
181181
),
182182
]).toList(),
183-
validator: V.required(V.isInList(validBloodTypeOptions,
184-
isInListMsg: (_, List<String> v) =>
183+
validator: V.required(V.inList(validBloodTypeOptions,
184+
inListMsg: (_, List<String> v) =>
185185
'The option must be one of: ${v.join(', ')}.')),
186186
onChanged: (String? value) {
187187
setState(() {

lib/src/form_builder_validators.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3480,7 +3480,7 @@ final class Validators {
34803480
maxInclusive: rightInclusive);
34813481

34823482
// Generic type validators
3483-
/// {@template validator_is_in_list}
3483+
/// {@template validator_in_list}
34843484
/// Creates a validator function that verifies if a given input is in `values`.
34853485
///
34863486
/// ## Type Parameters
@@ -3490,7 +3490,7 @@ final class Validators {
34903490
/// ## Parameters
34913491
/// - `values` (`List<T>`): A non-empty list of valid values to check against. The input
34923492
/// will be validated against these values.
3493-
/// - `isInListMsg` (`String Function(T input, List<T> values)?`): Optional callback
3493+
/// - `inListMsg` (`String Function(T input, List<T> values)?`): Optional callback
34943494
/// function that generates a custom error message when validation fails. The function
34953495
/// receives the invalid input and the list of valid values as parameters. If not provided,
34963496
/// defaults to the localized error text from FormBuilderLocalizations.
@@ -3507,7 +3507,7 @@ final class Validators {
35073507
/// ## Examples
35083508
/// ```dart
35093509
/// // Creating a validator with a custom error message generator
3510-
/// final countryValidator = isInList(
3510+
/// final countryValidator = Validators.inList(
35113511
/// ['USA', 'Canada', 'Mexico'],
35123512
/// isInListMsg: (input, values) =>
35133513
/// 'Country $input is not in allowed list: ${values.join(", ")}',
@@ -3518,11 +3518,11 @@ final class Validators {
35183518
/// final valid = countryValidator('USA'); // Returns null (valid)
35193519
/// ```
35203520
/// {@endtemplate}
3521-
static Validator<T> isInList<T extends Object?>(
3521+
static Validator<T> inList<T extends Object?>(
35223522
List<T> values, {
3523-
String Function(T input, List<T> values)? isInListMsg,
3523+
String Function(T input, List<T> values)? inListMsg,
35243524
}) =>
3525-
val.isInList(values, isInListMsg: isInListMsg);
3525+
val.inList(values, inListMsg: inListMsg);
35263526

35273527
/// {@template validator_is_true}
35283528
/// Creates a validator function that checks if a given input represents a `true`

lib/src/validators/generic_type_validators.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import '../../localization/l10n.dart';
22
import 'constants.dart';
33

4-
/// {@macro validator_is_in_list}
5-
Validator<T> isInList<T extends Object?>(
4+
/// {@macro validator_in_list}
5+
Validator<T> inList<T extends Object?>(
66
List<T> values, {
7-
String Function(T input, List<T> values)? isInListMsg,
7+
String Function(T input, List<T> values)? inListMsg,
88
}) {
99
if (values.isEmpty) {
1010
throw ArgumentError.value(
@@ -14,7 +14,7 @@ Validator<T> isInList<T extends Object?>(
1414
return (T input) {
1515
return setOfValues.contains(input)
1616
? null
17-
: isInListMsg?.call(input, values) ??
17+
: inListMsg?.call(input, values) ??
1818
FormBuilderLocalizations.current.containsElementErrorText;
1919
};
2020
}
@@ -39,7 +39,7 @@ Validator<T> isTrue<T extends Object>(
3939
};
4040
}
4141

42-
/// {@macro validator_is_false}
42+
/// {@macro validator_false}
4343
Validator<T> isFalse<T extends Object>(
4444
{String Function(T input)? isFalseMsg,
4545
bool caseSensitive = false,

test/src/validators/generic_type_validators/is_in_list_validator_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ void main() {
66
group('Validator: isInList', () {
77
group('Validations with default error message', () {
88
test('Should return null when int 0 is provided', () {
9-
final Validator<int> validator = isInList(<int>[0]);
9+
final Validator<int> validator = inList(<int>[0]);
1010

1111
expect(validator(0), isNull);
1212
expect(validator(2),
1313
equals(FormBuilderLocalizations.current.containsElementErrorText));
1414
});
1515
test('Should return null when int 0 or String "2" is provided', () {
16-
final Validator<Object> validator = isInList(<Object>[0, '2']);
16+
final Validator<Object> validator = inList(<Object>[0, '2']);
1717

1818
expect(validator(0), isNull);
1919
expect(validator('2'), isNull);
2020
expect(validator(2),
2121
equals(FormBuilderLocalizations.current.containsElementErrorText));
2222
});
2323
test('Should return null when int 0, int 2, or null is provided', () {
24-
final Validator<Object?> validator = isInList(<Object?>[0, 2, null]);
24+
final Validator<Object?> validator = inList(<Object?>[0, 2, null]);
2525

2626
expect(validator(0), isNull);
2727
expect(validator(2), isNull);
@@ -32,22 +32,22 @@ void main() {
3232
});
3333

3434
test('Should throw ArgumentError when list input is empty', () {
35-
expect(() => isInList(<Object>[]), throwsArgumentError);
35+
expect(() => inList(<Object>[]), throwsArgumentError);
3636
});
3737

3838
test('Should return custom error message when invalid input is provided',
3939
() {
4040
const String customMessage = 'custom message';
4141
final Validator<int> validator =
42-
isInList(<int>[1, 2, 3], isInListMsg: (_, __) => customMessage);
42+
inList(<int>[1, 2, 3], inListMsg: (_, __) => customMessage);
4343

4444
expect(validator(4), equals(customMessage));
4545
});
4646

4747
test('should remain immutable when input elements change', () {
4848
final List<Object> elements = <Object>[12, 15, 'hi'];
4949

50-
final Validator<Object> v = isInList(elements);
50+
final Validator<Object> v = inList(elements);
5151

5252
expect(v(12), isNull);
5353
expect(v(15), isNull);

0 commit comments

Comments
 (0)