Skip to content

Commit aa8f96d

Browse files
committed
Added type safety to equal validator, along with a unit test.
1 parent 1aa5759 commit aa8f96d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/src/form_builder_validators.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class FormBuilderValidators {
3939

4040
/// [FormFieldValidator] that requires the field's value be true.
4141
/// Commonly used for required checkboxes.
42-
static FormFieldValidator equal(
42+
static FormFieldValidator<T> equal<T>(
4343
BuildContext context,
44-
dynamic value, {
44+
T value, {
4545
String errorText,
4646
}) =>
4747
(valueCandidate) => valueCandidate != value

test/form_builder_validators_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ void main() {
4444
expect(validator([]), isNotNull);
4545
}));
4646

47+
testWidgets(
48+
'FormBuilderValidators.equal',
49+
(WidgetTester tester) => testValidations(tester, (context) {
50+
final validator = FormBuilderValidators.equal(context, true);
51+
// Pass
52+
expect(validator(true), isNull);
53+
// Fail
54+
expect(validator(null), isNotNull);
55+
expect(validator(false), isNotNull);
56+
}));
57+
4758
testWidgets(
4859
'FormBuilderValidators.maxLength',
4960
(WidgetTester tester) => testValidations(tester, (context) {

0 commit comments

Comments
 (0)