Skip to content

Commit 6038944

Browse files
committed
Null safety
1 parent c1534cd commit 6038944

File tree

151 files changed

+247
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+247
-208
lines changed

lib/src/base_validator.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,15 @@ abstract class BaseValidator<T> {
2222

2323
/// Validates the value and checks if it is null or empty.
2424
String? validate(T? valueCandidate) {
25-
if (checkNullOrEmpty && isNullOrEmpty(valueCandidate)) {
25+
final bool isNullOrEmpty = this.isNullOrEmpty(valueCandidate);
26+
27+
if (checkNullOrEmpty && isNullOrEmpty) {
2628
return errorText;
29+
} else if (!checkNullOrEmpty && isNullOrEmpty) {
30+
return null;
31+
} else {
32+
return validateValue(valueCandidate as T);
2733
}
28-
return validateValue(valueCandidate);
2934
}
3035

3136
/// Checks if the value is null or empty.
@@ -43,5 +48,5 @@ abstract class BaseValidator<T> {
4348

4449
/// Validates the value.
4550
/// Returns `null` if the value is valid, otherwise an error message.
46-
String? validateValue(T? valueCandidate);
51+
String? validateValue(T valueCandidate);
4752
}

lib/src/bool/has_lowercase_chars_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class HasLowercaseCharsValidator extends BaseValidator<String> {
3434
static final RegExp _lowerCase = RegExp('[^a-zñ]');
3535

3636
@override
37-
String? validateValue(String? valueCandidate) {
38-
return lowercaseCharLength(valueCandidate!) >= atLeast ? null : errorText;
37+
String? validateValue(String valueCandidate) {
38+
return lowercaseCharLength(valueCandidate) >= atLeast ? null : errorText;
3939
}
4040

4141
int lowercaseCharLength(String value) {

lib/src/bool/has_numeric_chars_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class HasNumericCharsValidator extends BaseValidator<String> {
3434
static final RegExp _number = RegExp('[^0-9]');
3535

3636
@override
37-
String? validateValue(String? valueCandidate) {
38-
return numberCharLength(valueCandidate!) >= atLeast ? null : errorText;
37+
String? validateValue(String valueCandidate) {
38+
return numberCharLength(valueCandidate) >= atLeast ? null : errorText;
3939
}
4040

4141
int numberCharLength(String value) {

lib/src/bool/has_special_chars_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class HasSpecialCharsValidator extends BaseValidator<String> {
3434
static final RegExp _specialChar = RegExp('[A-Za-z0-9]');
3535

3636
@override
37-
String? validateValue(String? valueCandidate) {
38-
return specialCharLength(valueCandidate!) >= atLeast ? null : errorText;
37+
String? validateValue(String valueCandidate) {
38+
return specialCharLength(valueCandidate) >= atLeast ? null : errorText;
3939
}
4040

4141
int specialCharLength(String value) {

lib/src/bool/has_uppercase_chars_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class HasUppercaseCharsValidator extends BaseValidator<String> {
3434
static final RegExp _upperCase = RegExp('[^A-ZÑ]');
3535

3636
@override
37-
String? validateValue(String? valueCandidate) {
38-
return uppercaseCharLength(valueCandidate!) >= 1 ? null : errorText;
37+
String? validateValue(String valueCandidate) {
38+
return uppercaseCharLength(valueCandidate) >= 1 ? null : errorText;
3939
}
4040

4141
int uppercaseCharLength(String value) {

lib/src/bool/is_false_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IsFalseValidator extends BaseValidator<bool> {
1515
FormBuilderLocalizations.current.mustBeFalseErrorText;
1616

1717
@override
18-
String? validateValue(bool? valueCandidate) {
19-
return valueCandidate ?? false ? null : errorText;
18+
String? validateValue(bool valueCandidate) {
19+
return valueCandidate == false ? null : errorText;
2020
}
2121
}

lib/src/bool/is_true_validator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class IsTrueValidator extends BaseValidator<bool> {
1515
FormBuilderLocalizations.current.mustBeTrueErrorText;
1616

1717
@override
18-
String? validateValue(bool? valueCandidate) {
19-
return valueCandidate ?? true ? null : errorText;
18+
String? validateValue(bool valueCandidate) {
19+
return valueCandidate == true ? null : errorText;
2020
}
2121
}

lib/src/collection/contains_element_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ContainsElementValidator<T> extends BaseValidator<T> {
1818
FormBuilderLocalizations.current.containsElementErrorText;
1919

2020
@override
21-
String? validateValue(T? valueCandidate) {
21+
String? validateValue(T valueCandidate) {
2222
return values.contains(valueCandidate) ? null : errorText;
2323
}
2424
}

lib/src/collection/equal_length_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class EqualLengthValidator<T> extends BaseValidator<T> {
2222
FormBuilderLocalizations.current.equalLengthErrorText(length);
2323

2424
@override
25-
String? validateValue(T? valueCandidate) {
25+
String? validateValue(T valueCandidate) {
2626
int valueLength = 0;
2727

2828
if (valueCandidate is String) valueLength = valueCandidate.length;

lib/src/collection/max_length_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MaxLengthValidator<T> extends BaseValidator<T> {
1818
FormBuilderLocalizations.current.equalLengthErrorText(maxLength);
1919

2020
@override
21-
String? validateValue(T? valueCandidate) {
21+
String? validateValue(T valueCandidate) {
2222
int valueLength = 0;
2323

2424
if (valueCandidate is String) valueLength = valueCandidate.length;

0 commit comments

Comments
 (0)