@@ -72,9 +72,13 @@ class FormBuilderValidators {
72
72
/// greater than or equal to the provided minimum length.
73
73
static FormFieldValidator minLength (
74
74
num minLength, {
75
+ bool allowEmpty = false ,
75
76
String errorText,
76
77
}) {
77
78
return (valueCandidate) {
79
+ if (allowEmpty && (valueCandidate == null || valueCandidate? .length == 0 ))
80
+ return errorText ??
81
+ "Value must have a length greater than or equal to $minLength " ;
78
82
if (valueCandidate != null && valueCandidate.length < minLength) {
79
83
return errorText ??
80
84
"Value must have a length greater than or equal to $minLength " ;
@@ -88,8 +92,13 @@ class FormBuilderValidators {
88
92
static FormFieldValidator maxLength (
89
93
num maxLength, {
90
94
String errorText,
95
+ bool allowEmpty = false ,
91
96
}) {
92
97
return (valueCandidate) {
98
+ if (allowEmpty && (valueCandidate == null || valueCandidate? .length == 0 ))
99
+ return errorText ??
100
+ "Value must have a length greater than or equal to $minLength " ;
101
+
93
102
if (valueCandidate != null && valueCandidate.length > maxLength) {
94
103
return errorText ??
95
104
"Value must have a length less than or equal to $maxLength " ;
@@ -111,14 +120,15 @@ class FormBuilderValidators {
111
120
}
112
121
113
122
/// [FormFieldValidator] that requires the field's value to be a valid url.
114
- static FormFieldValidator url (
115
- {String errorText = "This field requires a valid URL address." ,
116
- List <String > protocols = const ['http' , 'https' , 'ftp' ],
117
- bool requireTld = true ,
118
- bool requireProtocol = false ,
119
- bool allowUnderscore = false ,
120
- List <String > hostWhitelist = const [],
121
- List <String > hostBlacklist = const []}) {
123
+ static FormFieldValidator url ({
124
+ String errorText = "This field requires a valid URL address." ,
125
+ List <String > protocols = const ['http' , 'https' , 'ftp' ],
126
+ bool requireTld = true ,
127
+ bool requireProtocol = false ,
128
+ bool allowUnderscore = false ,
129
+ List <String > hostWhitelist = const [],
130
+ List <String > hostBlacklist = const [],
131
+ }) {
122
132
return (valueCandidate) {
123
133
if (valueCandidate != null && valueCandidate.isNotEmpty) {
124
134
if (! isURL (valueCandidate,
0 commit comments