Skip to content

Commit 323723a

Browse files
committed
Fixes
1 parent a21c3fd commit 323723a

14 files changed

+109
-106
lines changed

lib/src/numeric/max_validator.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ class MaxValidator<T> extends BaseValidator<T> {
2323

2424
@override
2525
String? validateValue(T valueCandidate) {
26-
final num value;
27-
switch (T) {
28-
case String:
29-
value = num.tryParse(valueCandidate! as String)!;
30-
case num:
31-
value = valueCandidate! as num;
32-
default:
33-
return errorText;
26+
final num? value;
27+
28+
if (valueCandidate is String) {
29+
value = num.tryParse(valueCandidate);
30+
} else if (valueCandidate is num) {
31+
value = valueCandidate;
32+
} else {
33+
return errorText;
34+
}
35+
36+
if (value == null) {
37+
return errorText;
3438
}
3539

3640
if (inclusive) {

lib/src/numeric/min_validator.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ class MinValidator<T> extends BaseValidator<T> {
2323

2424
@override
2525
String? validateValue(T valueCandidate) {
26-
final num value;
27-
switch (T) {
28-
case String:
29-
value = num.tryParse(valueCandidate! as String)!;
30-
case num:
31-
value = valueCandidate! as num;
32-
default:
33-
return errorText;
26+
final num? value;
27+
if (valueCandidate is String) {
28+
value = num.tryParse(valueCandidate);
29+
} else if (valueCandidate is num) {
30+
value = valueCandidate;
31+
} else {
32+
return errorText;
33+
}
34+
35+
if (value == null) {
36+
return errorText;
3437
}
3538

3639
if (inclusive) {

lib/src/numeric/negative_number_validator.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ class NegativeNumberValidator<T> extends BaseValidator<T> {
1616

1717
@override
1818
String? validateValue(T valueCandidate) {
19-
final num value;
20-
switch (T) {
21-
case String:
22-
value = num.tryParse(valueCandidate! as String)!;
23-
case num:
24-
value = valueCandidate! as num;
25-
default:
26-
return errorText;
19+
final num? value;
20+
if (valueCandidate is String) {
21+
value = num.tryParse(valueCandidate);
22+
} else if (valueCandidate is num) {
23+
value = valueCandidate;
24+
} else {
25+
return errorText;
26+
}
27+
28+
if (value == null) {
29+
return errorText;
2730
}
2831

2932
if (value >= 0) {

lib/src/numeric/not_zero_number_validator.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ class NotZeroNumberValidator<T> extends BaseValidator<T> {
1616

1717
@override
1818
String? validateValue(T valueCandidate) {
19-
final num value;
20-
switch (T) {
21-
case String:
22-
value = num.tryParse(valueCandidate! as String)!;
23-
case num:
24-
value = valueCandidate! as num;
25-
default:
26-
return errorText;
19+
final num? value;
20+
if (valueCandidate is String) {
21+
value = num.tryParse(valueCandidate);
22+
} else if (valueCandidate is num) {
23+
value = valueCandidate;
24+
} else {
25+
return errorText;
26+
}
27+
28+
if (value == null) {
29+
return errorText;
2730
}
2831

2932
if (value == 0) {

lib/src/numeric/numeric_validator.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ class NumericValidator<T> extends BaseValidator<T> {
1717
@override
1818
String? validateValue(T valueCandidate) {
1919
final num? value;
20-
switch (T) {
21-
case String:
22-
value = num.tryParse(valueCandidate! as String);
23-
case num:
24-
value = valueCandidate! as num;
25-
default:
26-
return errorText;
20+
if (valueCandidate is String) {
21+
value = num.tryParse(valueCandidate);
22+
} else if (valueCandidate is num) {
23+
value = valueCandidate;
24+
} else {
25+
return errorText;
2726
}
2827

2928
return value == null ? errorText : null;

lib/src/numeric/positive_number_validator.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ class PositiveNumberValidator<T> extends BaseValidator<T> {
1616

1717
@override
1818
String? validateValue(T valueCandidate) {
19-
final num value;
20-
switch (T) {
21-
case String:
22-
value = num.tryParse(valueCandidate! as String)!;
23-
case num:
24-
value = valueCandidate! as num;
25-
default:
26-
return errorText;
19+
final num? value;
20+
if (valueCandidate is String) {
21+
value = num.tryParse(valueCandidate);
22+
} else if (valueCandidate is num) {
23+
value = valueCandidate;
24+
} else {
25+
return errorText;
26+
}
27+
28+
if (value == null) {
29+
return errorText;
2730
}
2831

2932
if (value <= 0) {

lib/src/numeric/range_validator.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,11 @@ class RangeValidator<T> extends BaseValidator<T> {
6161
final String? maxLengthResult =
6262
_maxLengthValidator.validate(valueCandidate);
6363

64-
if (minResult == null &&
65-
maxResult == null &&
66-
minLengthResult == null &&
67-
maxLengthResult == null) {
64+
if ((minResult == null && maxResult == null) ||
65+
(minLengthResult == null && maxLengthResult == null)) {
6866
return null;
6967
} else {
70-
return minResult ??
71-
maxResult ??
72-
minLengthResult ??
73-
maxLengthResult ??
74-
errorText;
68+
return errorText;
7569
}
7670
}
7771
}

lib/src/string/match_not_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class MatchNotValidator extends BaseValidator<String> {
1919

2020
@override
2121
String? validateValue(String valueCandidate) {
22-
return regex.hasMatch(valueCandidate) ? null : errorText;
22+
return !regex.hasMatch(valueCandidate) ? errorText : null;
2323
}
2424
}

lib/src/string/match_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class MatchValidator extends BaseValidator<String> {
1919

2020
@override
2121
String? validateValue(String valueCandidate) {
22-
return !regex.hasMatch(valueCandidate) ? null : errorText;
22+
return regex.hasMatch(valueCandidate) ? null : errorText;
2323
}
2424
}

lib/src/string/single_line_validator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SingleLineValidator extends BaseValidator<String> {
1616

1717
@override
1818
String? validateValue(String valueCandidate) {
19-
return !valueCandidate.contains('\n') && !valueCandidate.contains('\r')
19+
return valueCandidate.contains('\n') || valueCandidate.contains('\r')
2020
? errorText
2121
: null;
2222
}

0 commit comments

Comments
 (0)