mnemo_cards/lib/utils/string_helper.dart

26 lines
602 B
Dart
Raw Normal View History

2024-07-03 20:56:13 +00:00
import 'dart:ui';
2024-05-22 20:48:44 +00:00
extension StringHelper on String {
String get capitalize =>
"${this[0].toUpperCase()}${this.substring(1).toLowerCase()}";
Color? get asColor {
if (startsWith('#')) {
return replaceFirst('#', '0x').asColor;
}
if (startsWith('0x')) {
if (length > '0x001122'.length) {
return Color(int.parse(this));
} else {
return Color(0xff000000 + int.parse(this));
}
} else {
if (length == 'aabbcc'.length || length == 'ffaabbcc'.length) {
return '0x$this'.asColor;
}
}
2024-07-03 20:56:13 +00:00
return Color(0xffffffff);
2024-05-22 20:48:44 +00:00
}
}