Skip to content

Commit 5698e39

Browse files
committed
Color check
1 parent 5cc6aa4 commit 5698e39

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

lib/src/utils/validators.dart

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -293,37 +293,31 @@ bool isNotExpiredCreditCardDate(String str) {
293293

294294
bool isColorCode(String value,
295295
{List<String> formats = const ['hex', 'rgb', 'hsl']}) {
296-
if (formats.contains('hex')) {
297-
if (_hexRegExp.hasMatch(value)) return true;
298-
}
299-
if (formats.contains('rgb')) {
300-
if (_rgbRegExp.hasMatch(value)) {
301-
final parts = value.substring(4, value.length - 1).split(',');
302-
for (final part in parts) {
303-
final int colorValue = int.tryParse(part.trim()) ?? -1;
304-
if (colorValue < 0 || colorValue > 255) {
305-
return false;
306-
}
296+
if (formats.contains('hex') && _hexRegExp.hasMatch(value)) {
297+
return true;
298+
} else if (formats.contains('rgb') && _rgbRegExp.hasMatch(value)) {
299+
final parts = value.substring(4, value.length - 1).split(',');
300+
for (final part in parts) {
301+
final int colorValue = int.tryParse(part.trim()) ?? -1;
302+
if (colorValue < 0 || colorValue > 255) {
303+
return false;
307304
}
308-
return true;
309305
}
310-
}
311-
if (formats.contains('hsl')) {
312-
if (_hslRegExp.hasMatch(value)) {
313-
final parts = value.substring(4, value.length - 1).split(',');
314-
for (var i = 0; i < parts.length; i++) {
315-
final int colorValue = int.tryParse(parts[i].trim()) ?? -1;
316-
if (i == 0) {
317-
// Hue
318-
if (colorValue < 0 || colorValue > 360) {
319-
return false;
320-
}
321-
} else if (colorValue < 0 || colorValue > 100) {
306+
return true;
307+
} else if (formats.contains('hsl') && _hslRegExp.hasMatch(value)) {
308+
final parts = value.substring(4, value.length - 1).split(',');
309+
for (var i = 0; i < parts.length; i++) {
310+
final int colorValue = int.tryParse(parts[i].trim()) ?? -1;
311+
if (i == 0) {
312+
// Hue
313+
if (colorValue < 0 || colorValue > 360) {
322314
return false;
323315
}
316+
} else if (colorValue < 0 || colorValue > 100) {
317+
return false;
324318
}
325-
return true;
326319
}
320+
return true;
327321
}
328322
return false;
329323
}

0 commit comments

Comments
 (0)