File tree Expand file tree Collapse file tree 4 files changed +368
-157
lines changed Expand file tree Collapse file tree 4 files changed +368
-157
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
+ ## 11.0.1
4
+
5
+ - Align between validator input types with other validators
6
+
3
7
## 11.0.0
4
8
5
9
- Split up validators into smaller pieces
Original file line number Diff line number Diff line change @@ -1155,13 +1155,13 @@ class FormBuilderValidators {
1155
1155
/// or equal to.
1156
1156
/// - [errorText] The error message when the value is not in the range.
1157
1157
/// - [checkNullOrEmpty] Whether to check for null or empty values.
1158
- static FormFieldValidator <num > between (
1158
+ static FormFieldValidator <T > between < T > (
1159
1159
num min,
1160
1160
num max, {
1161
1161
String ? errorText,
1162
1162
bool checkNullOrEmpty = true ,
1163
1163
}) =>
1164
- BetweenValidator (
1164
+ BetweenValidator < T > (
1165
1165
min,
1166
1166
max,
1167
1167
errorText: errorText,
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import '../base_validator.dart';
14
14
/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
15
15
///
16
16
/// {@endtemplate}
17
- class BetweenValidator extends BaseValidator <num > {
17
+ class BetweenValidator < T > extends BaseValidator <T > {
18
18
/// Constructor for the between validator.
19
19
const BetweenValidator (
20
20
this .min,
@@ -37,9 +37,18 @@ class BetweenValidator extends BaseValidator<num> {
37
37
FormBuilderLocalizations .current.betweenErrorText (min, max);
38
38
39
39
@override
40
- String ? validateValue (num valueCandidate) {
41
- final num value = valueCandidate;
42
- if (value < min || value > max) {
40
+ String ? validateValue (T valueCandidate) {
41
+ final num ? value;
42
+
43
+ if (valueCandidate is String ) {
44
+ value = num .tryParse (valueCandidate);
45
+ } else if (valueCandidate is num ) {
46
+ value = valueCandidate;
47
+ } else {
48
+ return errorText;
49
+ }
50
+
51
+ if (value == null || (value < min || value > max)) {
43
52
return errorText;
44
53
}
45
54
You can’t perform that action at this time.
0 commit comments