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 11# Changelog
22
3+ ## 11.0.1
4+
5+ - Align between validator input types with other validators
6+
37## 11.0.0
48
59- Split up validators into smaller pieces
Original file line number Diff line number Diff line change @@ -1155,13 +1155,13 @@ class FormBuilderValidators {
11551155 /// or equal to.
11561156 /// - [errorText] The error message when the value is not in the range.
11571157 /// - [checkNullOrEmpty] Whether to check for null or empty values.
1158- static FormFieldValidator <num > between (
1158+ static FormFieldValidator <T > between < T > (
11591159 num min,
11601160 num max, {
11611161 String ? errorText,
11621162 bool checkNullOrEmpty = true ,
11631163 }) =>
1164- BetweenValidator (
1164+ BetweenValidator < T > (
11651165 min,
11661166 max,
11671167 errorText: errorText,
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import '../base_validator.dart';
1414/// - [checkNullOrEmpty] Whether to check if the value is null or empty.
1515///
1616/// {@endtemplate}
17- class BetweenValidator extends BaseValidator <num > {
17+ class BetweenValidator < T > extends BaseValidator <T > {
1818 /// Constructor for the between validator.
1919 const BetweenValidator (
2020 this .min,
@@ -37,9 +37,18 @@ class BetweenValidator extends BaseValidator<num> {
3737 FormBuilderLocalizations .current.betweenErrorText (min, max);
3838
3939 @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)) {
4352 return errorText;
4453 }
4554
You can’t perform that action at this time.
0 commit comments