@@ -63,6 +63,7 @@ class FormBuilderValidators {
63
63
}) {
64
64
return (valueCandidate) {
65
65
if (valueCandidate != null ) {
66
+ assert (valueCandidate is num || valueCandidate is String );
66
67
final number = valueCandidate is num
67
68
? valueCandidate
68
69
: num .tryParse (valueCandidate.toString ());
@@ -87,6 +88,7 @@ class FormBuilderValidators {
87
88
}) {
88
89
return (valueCandidate) {
89
90
if (valueCandidate != null ) {
91
+ assert (valueCandidate is num || valueCandidate is String );
90
92
final number = valueCandidate is num
91
93
? valueCandidate
92
94
: num .tryParse (valueCandidate.toString ());
@@ -108,7 +110,9 @@ class FormBuilderValidators {
108
110
bool allowEmpty = false ,
109
111
String errorText,
110
112
}) {
113
+ assert (minLength > 0 );
111
114
return (valueCandidate) {
115
+ assert (null == valueCandidate || valueCandidate is String );
112
116
final valueLength = valueCandidate? .length ?? 0 ;
113
117
if (valueLength < minLength && (! allowEmpty || valueLength > 0 )) {
114
118
return errorText ??
@@ -125,10 +129,15 @@ class FormBuilderValidators {
125
129
num maxLength, {
126
130
String errorText,
127
131
}) {
132
+ assert (maxLength > 0 );
128
133
return (valueCandidate) {
129
- if (valueCandidate != null && valueCandidate.length > maxLength) {
130
- return errorText ??
131
- FormBuilderLocalizations .of (context).maxLengthErrorText (maxLength);
134
+ if (null != valueCandidate) {
135
+ assert (valueCandidate is String );
136
+ if (valueCandidate.length > maxLength) {
137
+ return errorText ??
138
+ FormBuilderLocalizations .of (context)
139
+ .maxLengthErrorText (maxLength);
140
+ }
132
141
}
133
142
return null ;
134
143
};
@@ -140,8 +149,9 @@ class FormBuilderValidators {
140
149
String errorText,
141
150
}) {
142
151
return (valueCandidate) {
143
- if (valueCandidate != null && valueCandidate.isNotEmpty) {
144
- if (! isEmail (valueCandidate.trim ())) {
152
+ if (null != valueCandidate) {
153
+ assert (valueCandidate is String );
154
+ if (valueCandidate.isNotEmpty && ! isEmail (valueCandidate.trim ())) {
145
155
return errorText ??
146
156
FormBuilderLocalizations .of (context).emailErrorText;
147
157
}
@@ -162,14 +172,16 @@ class FormBuilderValidators {
162
172
List <String > hostBlacklist = const [],
163
173
}) {
164
174
return (valueCandidate) {
165
- if (valueCandidate != null && valueCandidate.isNotEmpty) {
166
- if (! isURL (valueCandidate,
167
- protocols: protocols,
168
- requireTld: requireTld,
169
- requireProtocol: requireProtocol,
170
- allowUnderscore: allowUnderscore,
171
- hostWhitelist: hostWhitelist,
172
- hostBlacklist: hostBlacklist)) {
175
+ if (null != valueCandidate) {
176
+ assert (valueCandidate is String );
177
+ if (valueCandidate.isNotEmpty &&
178
+ ! isURL (valueCandidate,
179
+ protocols: protocols,
180
+ requireTld: requireTld,
181
+ requireProtocol: requireProtocol,
182
+ allowUnderscore: allowUnderscore,
183
+ hostWhitelist: hostWhitelist,
184
+ hostBlacklist: hostBlacklist)) {
173
185
return errorText ?? FormBuilderLocalizations .of (context).urlErrorText;
174
186
}
175
187
}
@@ -184,8 +196,10 @@ class FormBuilderValidators {
184
196
String errorText,
185
197
}) {
186
198
return (valueCandidate) {
187
- if (valueCandidate != null && valueCandidate.isNotEmpty) {
188
- if (! RegExp (pattern).hasMatch (valueCandidate)) {
199
+ if (null != valueCandidate) {
200
+ assert (valueCandidate is String );
201
+ if (valueCandidate.isNotEmpty &&
202
+ ! RegExp (pattern).hasMatch (valueCandidate)) {
189
203
return errorText ??
190
204
FormBuilderLocalizations .of (context).matchErrorText;
191
205
}
@@ -200,9 +214,12 @@ class FormBuilderValidators {
200
214
String errorText,
201
215
}) {
202
216
return (valueCandidate) {
203
- if (valueCandidate.isNotEmpty && num .tryParse (valueCandidate) == null ) {
204
- return errorText ??
205
- FormBuilderLocalizations .of (context).numericErrorText;
217
+ if (null != valueCandidate) {
218
+ assert (valueCandidate is String );
219
+ if (valueCandidate.isNotEmpty && num .tryParse (valueCandidate) == null ) {
220
+ return errorText ??
221
+ FormBuilderLocalizations .of (context).numericErrorText;
222
+ }
206
223
}
207
224
return null ;
208
225
};
@@ -215,10 +232,13 @@ class FormBuilderValidators {
215
232
int radix,
216
233
}) {
217
234
return (valueCandidate) {
218
- if (valueCandidate.isNotEmpty &&
219
- int .tryParse (valueCandidate, radix: radix) == null ) {
220
- return errorText ??
221
- FormBuilderLocalizations .of (context).numericErrorText;
235
+ if (null != valueCandidate) {
236
+ assert (valueCandidate is String );
237
+ if (valueCandidate.isNotEmpty &&
238
+ int .tryParse (valueCandidate, radix: radix) == null ) {
239
+ return errorText ??
240
+ FormBuilderLocalizations .of (context).numericErrorText;
241
+ }
222
242
}
223
243
return null ;
224
244
};
@@ -231,10 +251,13 @@ class FormBuilderValidators {
231
251
String errorText,
232
252
}) {
233
253
return (valueCandidate) {
234
- if (valueCandidate.isNotEmpty &&
235
- double .tryParse (valueCandidate) == null ) {
236
- return errorText ??
237
- FormBuilderLocalizations .of (context).numericErrorText;
254
+ if (null != valueCandidate) {
255
+ assert (valueCandidate is String );
256
+ if (valueCandidate.isNotEmpty &&
257
+ double .tryParse (valueCandidate) == null ) {
258
+ return errorText ??
259
+ FormBuilderLocalizations .of (context).numericErrorText;
260
+ }
238
261
}
239
262
return null ;
240
263
};
@@ -246,8 +269,9 @@ class FormBuilderValidators {
246
269
String errorText,
247
270
}) {
248
271
return (valueCandidate) {
249
- if (valueCandidate != null && valueCandidate.isNotEmpty) {
250
- if (! isCreditCard (valueCandidate)) {
272
+ if (null != valueCandidate) {
273
+ assert (valueCandidate is String );
274
+ if (valueCandidate.isNotEmpty && ! isCreditCard (valueCandidate)) {
251
275
return errorText ??
252
276
FormBuilderLocalizations .of (context).creditCardErrorText;
253
277
}
@@ -265,8 +289,9 @@ class FormBuilderValidators {
265
289
String errorText,
266
290
}) {
267
291
return (valueCandidate) {
268
- if (valueCandidate != null && valueCandidate.isNotEmpty) {
269
- if (! isIP (valueCandidate, version)) {
292
+ if (null != valueCandidate) {
293
+ assert (valueCandidate is String );
294
+ if (valueCandidate.isNotEmpty && ! isIP (valueCandidate, version)) {
270
295
return errorText ?? FormBuilderLocalizations .of (context).ipErrorText;
271
296
}
272
297
}
@@ -280,8 +305,9 @@ class FormBuilderValidators {
280
305
String errorText,
281
306
}) {
282
307
return (valueCandidate) {
283
- if (valueCandidate != null && valueCandidate.isNotEmpty) {
284
- if (! isDate (valueCandidate)) {
308
+ if (null != valueCandidate) {
309
+ assert (valueCandidate is String );
310
+ if (valueCandidate.isNotEmpty && ! isDate (valueCandidate)) {
285
311
return errorText ??
286
312
FormBuilderLocalizations .of (context).dateStringErrorText;
287
313
}
0 commit comments