Skip to content

Commit fb39492

Browse files
committed
Fixes
1 parent 0eea535 commit fb39492

File tree

3 files changed

+0
-96
lines changed

3 files changed

+0
-96
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ Available built-in helper validators:
5252
- `FormBuilderValidators.conditional()` - conditionally runs a validator against the value provided.
5353
- `FormBuilderValidators.or()` - runs each validator against the value provided and passes when any works.
5454
- `FormBuilderValidators.transform()` - transforms the value before running the validator.
55-
- `FormBuilderValidators.debounce()` - runs the validator after a set time.
56-
- `FormBuilderValidators.retry()` - runs the validator again after failing while waiting a certain time.
5755
- `FormBuilderValidators.aggregate()` - runs the validators in parallel, collecting all errors.
5856
- `FormBuilderValidators.log()` - runs the validator and logs the value at a specific point in the validation chain.
5957
- `FormBuilderValidators.skipWhen()` - runs the validator and skips the validation when a certain condition is met.

lib/src/form_builder_validators.dart

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -60,52 +60,6 @@ class FormBuilderValidators {
6060
};
6161
}
6262

63-
/// [FormFieldValidator] that debounces the validation.
64-
/// * [duration] is the duration to wait before running the validation.
65-
/// * [validator] is the validator to debounce.
66-
static FormFieldValidator<T> debounce<T>({
67-
required Duration duration,
68-
required FormFieldValidator<T> validator,
69-
}) {
70-
Timer? debounceTimer;
71-
String? result;
72-
73-
return (valueCandidate) {
74-
debounceTimer?.cancel();
75-
debounceTimer = Timer(duration, () {
76-
result = validator(valueCandidate);
77-
});
78-
return result;
79-
};
80-
}
81-
82-
/// [FormFieldValidator] that retries the validation.
83-
/// * [times] is the number of times to retry the validation.
84-
/// * [duration] is the duration to wait before retrying the validation.
85-
/// * [validator] is the validator to retry.
86-
static FormFieldValidator<T> retry<T>({
87-
required int times,
88-
required Duration duration,
89-
required FormFieldValidator<T> validator,
90-
}) {
91-
int retries = 0;
92-
String? result;
93-
94-
return (valueCandidate) {
95-
if (retries < times) {
96-
result = validator(valueCandidate);
97-
if (result != null) {
98-
retries++;
99-
Future.delayed(duration, () {
100-
result = validator(valueCandidate);
101-
});
102-
}
103-
}
104-
105-
return result;
106-
};
107-
}
108-
10963
/// [FormFieldValidator] that runs validators and collects all errors.
11064
/// * [validators] is the list of validators to run.
11165
static FormFieldValidator<T> aggregate<T>(

test/form_builder_validators_test.dart

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,54 +1020,6 @@ void main() {
10201020
}),
10211021
);
10221022

1023-
testWidgets(
1024-
'FormBuilderValidators.debounce',
1025-
(WidgetTester tester) async {
1026-
String? validationResult;
1027-
final validator = FormBuilderValidators.debounce<String>(
1028-
duration: const Duration(milliseconds: 500),
1029-
validator: (value) => FormBuilderValidators.required()(value),
1030-
);
1031-
1032-
// Set initial result to null
1033-
validationResult = validator('valid');
1034-
// Initial pass check
1035-
expect(validationResult, isNull);
1036-
1037-
// Set result to not null but should still be null initially due to debounce
1038-
validationResult = validator('');
1039-
expect(validationResult, isNull);
1040-
1041-
// Advance time by 500 milliseconds to trigger debounce
1042-
await tester.pump(const Duration(milliseconds: 500));
1043-
1044-
// Validate again to see the actual result after debounce
1045-
validationResult = validator('');
1046-
expect(validationResult, isNotNull);
1047-
},
1048-
);
1049-
1050-
testWidgets(
1051-
'FormBuilderValidators.retry',
1052-
(WidgetTester tester) async {
1053-
int attempts = 0;
1054-
final validator = FormBuilderValidators.retry<String>(
1055-
times: 3,
1056-
duration: const Duration(milliseconds: 10),
1057-
validator: (value) {
1058-
attempts++;
1059-
return value != 'pass' && attempts < 3 ? 'fail' : null;
1060-
},
1061-
);
1062-
// Pass on retry
1063-
expect(validator('pass'), isNull);
1064-
// Fail after retries
1065-
expect(validator('fail'), isNotNull);
1066-
await Future.delayed(const Duration(milliseconds: 200));
1067-
expect(attempts, 3);
1068-
},
1069-
);
1070-
10711023
testWidgets(
10721024
'FormBuilderValidators.transform',
10731025
(WidgetTester tester) => testValidations(tester, (context) {

0 commit comments

Comments
 (0)