Skip to content

Commit 42ca441

Browse files
committed
Add extensions
1 parent 2e7070f commit 42ca441

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'package:flutter/material.dart';
2+
import '../form_builder_validators.dart';
3+
4+
extension FormFieldValidatorExtensions<T> on FormFieldValidator<T> {
5+
/// Combines the current validator with another validator using logical AND.
6+
FormFieldValidator<T> and(FormFieldValidator<T> other) {
7+
return FormBuilderValidators.compose([this, other]);
8+
}
9+
10+
/// Combines the current validator with another validator using logical OR.
11+
FormFieldValidator<T> or(FormFieldValidator<T> other) {
12+
return FormBuilderValidators.or([this, other]);
13+
}
14+
15+
/// Adds a condition to apply the validator only if the condition is met.
16+
FormFieldValidator<T> when(bool Function(T value) condition) {
17+
return FormBuilderValidators.conditional(condition, this);
18+
}
19+
}

0 commit comments

Comments
 (0)