Skip to content

Commit bae020e

Browse files
committed
Fixes
1 parent 72033b1 commit bae020e

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

lib/src/form_builder_validators.dart

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class FormBuilderValidators {
348348
List<String> hostWhitelist = const [],
349349
List<String> hostBlacklist = const [],
350350
}) =>
351-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
351+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
352352
!isURL(
353353
valueCandidate,
354354
protocols: protocols,
@@ -368,7 +368,7 @@ class FormBuilderValidators {
368368
String pattern, {
369369
String? errorText,
370370
}) =>
371-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
371+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
372372
!RegExp(pattern).hasMatch(valueCandidate!)
373373
? errorText ?? FormBuilderLocalizations.current.matchErrorText
374374
: null;
@@ -380,7 +380,7 @@ class FormBuilderValidators {
380380
String pattern, {
381381
String? errorText,
382382
}) =>
383-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
383+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
384384
RegExp(pattern).hasMatch(valueCandidate!)
385385
? errorText ?? FormBuilderLocalizations.current.matchErrorText
386386
: null;
@@ -390,7 +390,7 @@ class FormBuilderValidators {
390390
static FormFieldValidator<String> numeric({
391391
String? errorText,
392392
}) =>
393-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
393+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
394394
null == num.tryParse(valueCandidate!)
395395
? errorText ?? FormBuilderLocalizations.current.numericErrorText
396396
: null;
@@ -402,7 +402,7 @@ class FormBuilderValidators {
402402
String? errorText,
403403
int? radix,
404404
}) =>
405-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
405+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
406406
null == int.tryParse(valueCandidate!, radix: radix)
407407
? errorText ?? FormBuilderLocalizations.current.integerErrorText
408408
: null;
@@ -412,7 +412,7 @@ class FormBuilderValidators {
412412
static FormFieldValidator<String> creditCard({
413413
String? errorText,
414414
}) =>
415-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
415+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
416416
!isCreditCard(valueCandidate!)
417417
? errorText ?? FormBuilderLocalizations.current.creditCardErrorText
418418
: null;
@@ -424,7 +424,7 @@ class FormBuilderValidators {
424424
bool checkForExpiration = true,
425425
String? errorText,
426426
}) =>
427-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
427+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
428428
!isCreditCardExpirationDate(valueCandidate!)
429429
? errorText ??
430430
FormBuilderLocalizations.current.creditCardExpirationDateErrorText
@@ -457,7 +457,7 @@ class FormBuilderValidators {
457457
String? errorText,
458458
}) =>
459459
(valueCandidate) =>
460-
true == valueCandidate?.isNotEmpty && !isIP(valueCandidate, version)
460+
valueCandidate?.isNotEmpty == true && !isIP(valueCandidate, version)
461461
? errorText ?? FormBuilderLocalizations.current.ipErrorText
462462
: null;
463463

@@ -466,7 +466,7 @@ class FormBuilderValidators {
466466
static FormFieldValidator<String> dateString({
467467
String? errorText,
468468
}) =>
469-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
469+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
470470
!isDate(valueCandidate!)
471471
? errorText ?? FormBuilderLocalizations.current.dateStringErrorText
472472
: null;
@@ -515,7 +515,7 @@ class FormBuilderValidators {
515515
List<String> formats = const ['hex', 'rgb', 'hsl'],
516516
String? errorText,
517517
}) =>
518-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
518+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
519519
!isColorCode(valueCandidate!, formats: formats)
520520
? errorText ??
521521
FormBuilderLocalizations.current
@@ -527,7 +527,7 @@ class FormBuilderValidators {
527527
static FormFieldValidator<String> uppercase({
528528
String? errorText,
529529
}) =>
530-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
530+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
531531
valueCandidate!.toUpperCase() != valueCandidate
532532
? errorText ?? FormBuilderLocalizations.current.uppercaseErrorText
533533
: null;
@@ -537,7 +537,7 @@ class FormBuilderValidators {
537537
static FormFieldValidator<String> lowercase({
538538
String? errorText,
539539
}) =>
540-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
540+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
541541
valueCandidate!.toLowerCase() != valueCandidate
542542
? errorText ?? FormBuilderLocalizations.current.lowercaseErrorText
543543
: null;
@@ -661,7 +661,7 @@ class FormBuilderValidators {
661661
int atLeast = 1,
662662
String? errorText,
663663
}) =>
664-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
664+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
665665
specialCharLength(valueCandidate!) >= atLeast
666666
? null
667667
: errorText ??
@@ -675,7 +675,7 @@ class FormBuilderValidators {
675675
int atLeast = 1,
676676
String? errorText,
677677
}) =>
678-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
678+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
679679
uppercaseCharLength(valueCandidate!) >= atLeast
680680
? null
681681
: errorText ??
@@ -689,7 +689,7 @@ class FormBuilderValidators {
689689
int atLeast = 1,
690690
String? errorText,
691691
}) =>
692-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
692+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
693693
lowercaseCharLength(valueCandidate!) >= atLeast
694694
? null
695695
: errorText ??
@@ -703,7 +703,7 @@ class FormBuilderValidators {
703703
int atLeast = 1,
704704
String? errorText,
705705
}) =>
706-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
706+
(valueCandidate) => valueCandidate?.isNotEmpty == true &&
707707
numberCharLength(valueCandidate!) >= atLeast
708708
? null
709709
: errorText ??
@@ -751,8 +751,9 @@ class FormBuilderValidators {
751751
static FormFieldValidator<String> alphabetical({
752752
String? errorText,
753753
}) =>
754-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
755-
!isAlphabetical(valueCandidate!)
754+
(valueCandidate) => valueCandidate == null ||
755+
valueCandidate.isEmpty ||
756+
!isAlphabetical(valueCandidate)
756757
? errorText ?? FormBuilderLocalizations.current.alphabeticalErrorText
757758
: null;
758759

@@ -761,18 +762,19 @@ class FormBuilderValidators {
761762
static FormFieldValidator<String> uuid({
762763
String? errorText,
763764
}) =>
764-
(valueCandidate) =>
765-
true == valueCandidate?.isNotEmpty && !isUUID(valueCandidate!)
766-
? errorText ?? FormBuilderLocalizations.current.uuidErrorText
767-
: null;
765+
(valueCandidate) => valueCandidate == null ||
766+
valueCandidate.isEmpty ||
767+
!isUUID(valueCandidate)
768+
? errorText ?? FormBuilderLocalizations.current.uuidErrorText
769+
: null;
768770

769771
/// [FormFieldValidator] that requires the field's value to be valid json.
770772
/// * [errorText] is the error message to display when the json is invalid
771773
static FormFieldValidator<String> json({
772774
String? errorText,
773775
}) =>
774776
(valueCandidate) =>
775-
true == valueCandidate?.isNotEmpty && !isJSON(valueCandidate!)
777+
valueCandidate?.isEmpty != false || !isJSON(valueCandidate!)
776778
? errorText ?? FormBuilderLocalizations.current.jsonErrorText
777779
: null;
778780

@@ -782,7 +784,7 @@ class FormBuilderValidators {
782784
String? errorText,
783785
}) =>
784786
(valueCandidate) =>
785-
true == valueCandidate?.isNotEmpty && !isLatitude(valueCandidate!)
787+
valueCandidate?.isEmpty != false || !isLatitude(valueCandidate!)
786788
? errorText ?? FormBuilderLocalizations.current.latitudeErrorText
787789
: null;
788790

@@ -792,7 +794,7 @@ class FormBuilderValidators {
792794
String? errorText,
793795
}) =>
794796
(valueCandidate) =>
795-
true == valueCandidate?.isNotEmpty && !isLongitude(valueCandidate!)
797+
valueCandidate?.isEmpty != false || !isLongitude(valueCandidate!)
796798
? errorText ?? FormBuilderLocalizations.current.longitudeErrorText
797799
: null;
798800

@@ -802,7 +804,7 @@ class FormBuilderValidators {
802804
String? errorText,
803805
}) =>
804806
(valueCandidate) =>
805-
true == valueCandidate?.isNotEmpty && !isBase64(valueCandidate!)
807+
valueCandidate?.isEmpty != false || !isBase64(valueCandidate!)
806808
? errorText ?? FormBuilderLocalizations.current.base64ErrorText
807809
: null;
808810

@@ -812,7 +814,7 @@ class FormBuilderValidators {
812814
String? errorText,
813815
}) =>
814816
(valueCandidate) =>
815-
true == valueCandidate?.isNotEmpty && !isFilePath(valueCandidate!)
817+
valueCandidate?.isEmpty != false || !isFilePath(valueCandidate!)
816818
? errorText ?? FormBuilderLocalizations.current.pathErrorText
817819
: null;
818820

@@ -822,7 +824,7 @@ class FormBuilderValidators {
822824
String? errorText,
823825
}) =>
824826
(valueCandidate) =>
825-
true == valueCandidate?.isNotEmpty && !isOddNumber(valueCandidate!)
827+
valueCandidate?.isEmpty != false || !isOddNumber(valueCandidate!)
826828
? errorText ?? FormBuilderLocalizations.current.oddNumberErrorText
827829
: null;
828830

@@ -831,7 +833,7 @@ class FormBuilderValidators {
831833
static FormFieldValidator<String> evenNumber({
832834
String? errorText,
833835
}) =>
834-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
836+
(valueCandidate) => valueCandidate?.isEmpty != false ||
835837
!isEvenNumber(valueCandidate!)
836838
? errorText ?? FormBuilderLocalizations.current.evenNumberErrorText
837839
: null;
@@ -846,7 +848,7 @@ class FormBuilderValidators {
846848
String? errorText,
847849
}) =>
848850
(valueCandidate) {
849-
if (true == valueCandidate?.isNotEmpty) {
851+
if (valueCandidate?.isNotEmpty == true) {
850852
int? port = int.tryParse(valueCandidate!);
851853
if (port == null || port < min || port > max) {
852854
return errorText ??
@@ -864,7 +866,7 @@ class FormBuilderValidators {
864866
static FormFieldValidator<String> macAddress({
865867
String? errorText,
866868
}) =>
867-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
869+
(valueCandidate) => valueCandidate?.isEmpty != false ||
868870
!isMACAddress(valueCandidate!)
869871
? errorText ?? FormBuilderLocalizations.current.macAddressErrorText
870872
: null;
@@ -876,7 +878,7 @@ class FormBuilderValidators {
876878
required String prefix,
877879
String? errorText,
878880
}) =>
879-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
881+
(valueCandidate) => valueCandidate?.isEmpty != false ||
880882
!valueCandidate!.startsWith(prefix)
881883
? errorText ??
882884
FormBuilderLocalizations.current.startsWithErrorText(prefix)
@@ -889,11 +891,11 @@ class FormBuilderValidators {
889891
required String suffix,
890892
String? errorText,
891893
}) =>
892-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
893-
!valueCandidate!.endsWith(suffix)
894-
? errorText ??
895-
FormBuilderLocalizations.current.endsWithErrorText(suffix)
896-
: null;
894+
(valueCandidate) =>
895+
valueCandidate?.isEmpty != false || !valueCandidate!.endsWith(suffix)
896+
? errorText ??
897+
FormBuilderLocalizations.current.endsWithErrorText(suffix)
898+
: null;
897899

898900
/// [FormFieldValidator] that requires the field's value to contains a specific value.
899901
/// * [substring] is the value that the field's value should contain.
@@ -904,9 +906,8 @@ class FormBuilderValidators {
904906
bool caseSensitive = true,
905907
String? errorText,
906908
}) =>
907-
(valueCandidate) => true == valueCandidate?.isNotEmpty &&
908-
caseSensitive &&
909-
!valueCandidate!.contains(substring) ||
909+
(valueCandidate) => valueCandidate?.isEmpty != false ||
910+
caseSensitive && !valueCandidate!.contains(substring) ||
910911
!caseSensitive &&
911912
!valueCandidate!
912913
.toLowerCase()
@@ -947,7 +948,7 @@ class FormBuilderValidators {
947948
String? errorText,
948949
}) =>
949950
(valueCandidate) =>
950-
true == valueCandidate?.isNotEmpty && !isValidIban(valueCandidate!)
951+
valueCandidate?.isEmpty != false || !isValidIban(valueCandidate!)
951952
? errorText ?? FormBuilderLocalizations.current.ibanErrorText
952953
: null;
953954
}

0 commit comments

Comments
 (0)