Skip to content

Commit dec4504

Browse files
remove the verb 'is' from equality validators
1 parent 411dda1 commit dec4504

File tree

6 files changed

+36
-33
lines changed

6 files changed

+36
-33
lines changed

example/lib/basic_examples.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class BasicExamplesPage extends StatelessWidget {
3434
labelText:
3535
'Type "I want to delete" to confirm the action.'),
3636
autovalidateMode: AutovalidateMode.onUserInteraction,
37-
validator: Validators.isEqual('I want to delete'),
37+
validator: Validators.equal('I want to delete'),
3838
),
3939
TextFormField(
4040
decoration: const InputDecoration(
4141
labelText: 'Username (should not be "RESERVED")'),
4242
autovalidateMode: AutovalidateMode.onUserInteraction,
43-
validator: Validators.isNotEqual('RESERVED'),
43+
validator: Validators.notEqual('RESERVED'),
4444
),
4545
Align(
4646
alignment: Alignment.centerLeft,

example/lib/generic_examples.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class GenericExamplesPage extends StatelessWidget {
138138
labelText: 'Equal Field',
139139
prefixIcon: Icon(Icons.check),
140140
),
141-
validator: V.isEqual('test'),
141+
validator: V.equal('test'),
142142
textInputAction: TextInputAction.next,
143143
autovalidateMode: AutovalidateMode.always,
144144
),

lib/src/form_builder_validators.dart

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,8 @@ class FormBuilderValidators {
17381738
).validate;
17391739
}
17401740

1741+
//********************************* NEW API ********************************************************************************
1742+
17411743
/// A class that is used as an aggregator/namespace for all the available
17421744
/// validators in this package.
17431745
final class Validators {
@@ -1930,15 +1932,15 @@ final class Validators {
19301932
val.debugPrintValidator(next: next, logOnInput: logOnInput);
19311933

19321934
// Equality validators
1933-
/// {@template validator_is_equal}
1935+
/// {@template validator_equal}
19341936
/// Creates a validator that checks if a given input matches `referenceValue`
19351937
/// using the equality (`==`) operator.
19361938
///
19371939
///
19381940
/// ## Parameters
19391941
/// - `referenceValue` (`T`): The value to compare against the input. This serves as
19401942
/// the reference for equality checking.
1941-
/// - `isEqualMsg` (`String Function(T input, T referenceValue)?`): Optional
1943+
/// - `equalMsg` (`String Function(T input, T referenceValue)?`): Optional
19421944
/// custom error message generator. Takes the `input` and the `referenceValue`
19431945
/// as parameters and returns a custom error message.
19441946
///
@@ -1955,14 +1957,14 @@ final class Validators {
19551957
/// ## Examples
19561958
/// ```dart
19571959
/// // Basic usage for password confirmation
1958-
/// final confirmAction = isEqual('Type this to confirm the action');
1960+
/// final confirmAction = Validator.equal('Type this to confirm the action');
19591961
/// assert(confirmAction('Type this to confirm the action') == null); // null returned (validation passes)
19601962
/// assert(confirmAction(12345) != null); // Error message returned
19611963
///
19621964
/// // Using custom error message
1963-
/// final specificValueValidator = isEqual<int>(
1965+
/// final specificValueValidator = Validator.equal<int>(
19641966
/// 42,
1965-
/// isEqualMsg: (_, value) => 'Value must be exactly $value',
1967+
/// equalMsg: (_, value) => 'Value must be exactly $value',
19661968
/// );
19671969
/// ```
19681970
///
@@ -1972,20 +1974,20 @@ final class Validators {
19721974
/// - The error message uses the string representation of the value via
19731975
/// `toString()`, which might not be ideal for all types.
19741976
/// {@endtemplate}
1975-
static Validator<T> isEqual<T extends Object?>(
1977+
static Validator<T> equal<T extends Object?>(
19761978
T value, {
1977-
String Function(T input, T referenceValue)? isEqualMsg,
1979+
String Function(T input, T referenceValue)? equalMsg,
19781980
}) =>
1979-
val.isEqual(value, isEqualMsg: isEqualMsg);
1981+
val.equal(value, equalMsg: equalMsg);
19801982

1981-
/// {@template validator_is_not_equal}
1983+
/// {@template validator_not_equal}
19821984
/// Creates a validator that checks if a given input is not equal to
19831985
/// `referenceValue` using the not-equal (`!=`) operator.
19841986
///
19851987
/// ## Parameters
19861988
/// - `referenceValue` (`T`): The reference value to compare against. Input must
19871989
/// not equal this value to pass validation.
1988-
/// - `isNotEqualMsg` (`String Function(T input, T referenceValue)?`): Optional
1990+
/// - `notEqualMsg` (`String Function(T input, T referenceValue)?`): Optional
19891991
/// custom error message generator. Takes the `input` and the `referenceValue`
19901992
/// as parameters and returns a custom error message.
19911993
///
@@ -2001,14 +2003,14 @@ final class Validators {
20012003
/// ## Examples
20022004
/// ```dart
20032005
/// // Basic usage with strings
2004-
/// final validator = isNotEqual<String>('reserved');
2006+
/// final validator = Validators.notEqual<String>('reserved');
20052007
/// assert(validator('not-reserved') == null); // null (validation passes)
20062008
/// assert(validator('reserved') != null); // "Value must not be equal to reserved"
20072009
///
20082010
/// // Custom error message
2009-
/// final customValidator = isNotEqual<int>(
2011+
/// final customValidator = Validators.notEqual<int>(
20102012
/// 42,
2011-
/// isNotEqualMsg: (_, value) => 'Please choose a number other than $value',
2013+
/// notEqualMsg: (_, value) => 'Please choose a number other than $value',
20122014
/// );
20132015
/// ```
20142016
///
@@ -2018,13 +2020,14 @@ final class Validators {
20182020
/// - The error message uses the string representation of the value via
20192021
/// `toString()`, which might not be ideal for all types
20202022
/// {@endtemplate}
2021-
static Validator<T> isNotEqual<T extends Object?>(
2023+
static Validator<T> notEqual<T extends Object?>(
20222024
T value, {
2023-
String Function(T input, T referenceValue)? isNotEqualMsg,
2025+
String Function(T input, T referenceValue)? notEqualMsg,
20242026
}) =>
2025-
val.isNotEqual(value, isNotEqualMsg: isNotEqualMsg);
2027+
val.notEqual(value, notEqualMsg: notEqualMsg);
20262028

20272029
// Required validators
2030+
// TODO remove verb 'is' from validators
20282031
/// {@template validator_is_required}
20292032
/// Generates a validator function that enforces required field validation for
20302033
/// form inputs. This validator ensures that a field has a non-null, non-empty

lib/src/validators/core_validators/equality_validators.dart

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

4-
/// {@macro validator_is_equal}
5-
Validator<T> isEqual<T extends Object?>(
4+
/// {@macro validator_equal}
5+
Validator<T> equal<T extends Object?>(
66
T referenceValue, {
7-
String Function(T input, T referenceValue)? isEqualMsg,
7+
String Function(T input, T referenceValue)? equalMsg,
88
}) {
99
return (T input) {
1010
return referenceValue == input
1111
? null
12-
: isEqualMsg?.call(input, referenceValue) ??
12+
: equalMsg?.call(input, referenceValue) ??
1313
FormBuilderLocalizations.current
1414
.equalErrorText(referenceValue.toString());
1515
};
1616
}
1717

18-
/// {@macro validator_is_not_equal}
19-
Validator<T> isNotEqual<T extends Object?>(
18+
/// {@macro validator_not_equal}
19+
Validator<T> notEqual<T extends Object?>(
2020
T referenceValue, {
21-
String Function(T input, T referenceValue)? isNotEqualMsg,
21+
String Function(T input, T referenceValue)? notEqualMsg,
2222
}) {
2323
return (T input) {
2424
return referenceValue != input
2525
? null
26-
: isNotEqualMsg?.call(input, referenceValue) ??
26+
: notEqualMsg?.call(input, referenceValue) ??
2727
FormBuilderLocalizations.current
2828
.notEqualErrorText(referenceValue.toString());
2929
};

test/src/validators/core_validators/equality_validators/is_equal_validator_test.dart renamed to test/src/validators/core_validators/equality_validators/equal_validator_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class _CustomClass {}
77
void main() {
88
final _CustomClass myObject = _CustomClass();
99

10-
group('Validator: isEqual', () {
10+
group('Validator: equal', () {
1111
final List<
1212
({
1313
String description,
@@ -85,7 +85,7 @@ void main() {
8585
testFails: bool testFails
8686
) in testCases) {
8787
test(desc, () {
88-
final Validator<Object?> v = isEqual(referenceValue);
88+
final Validator<Object?> v = equal(referenceValue);
8989

9090
expect(
9191
v(userInput),
@@ -100,7 +100,7 @@ void main() {
100100
const String ref = 'hello';
101101
const String customErrorMessage = 'custom error';
102102
final Validator<Object> v =
103-
isEqual(ref, isEqualMsg: (_, __) => customErrorMessage);
103+
equal(ref, equalMsg: (_, __) => customErrorMessage);
104104

105105
// success
106106
expect(v(ref), isNull);

test/src/validators/core_validators/equality_validators/is_not_equal_validator_test.dart renamed to test/src/validators/core_validators/equality_validators/not_equal_validator_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class _CustomClass {}
77
void main() {
88
final _CustomClass myObject = _CustomClass();
99

10-
group('Validator: isNoEqual', () {
10+
group('Validator: notEqual', () {
1111
final List<
1212
({
1313
String description,
@@ -88,7 +88,7 @@ void main() {
8888
testFails: bool testFails
8989
) in testCases) {
9090
test(desc, () {
91-
final Validator<Object?> v = isNotEqual(referenceValue);
91+
final Validator<Object?> v = notEqual(referenceValue);
9292

9393
expect(
9494
v(userInput),
@@ -103,7 +103,7 @@ void main() {
103103
const String ref = 'hello';
104104
const String customErrorMessage = 'custom error';
105105
final Validator<Object> v =
106-
isNotEqual(ref, isNotEqualMsg: (_, __) => customErrorMessage);
106+
notEqual(ref, notEqualMsg: (_, __) => customErrorMessage);
107107

108108
// success
109109
expect(v(123), isNull);

0 commit comments

Comments
 (0)