mnemo_cards/lib/utils/string_helper.dart

25 lines
618 B
Dart
Raw Normal View History

2024-05-22 20:48:44 +00:00
import 'package:flutter/material.dart';
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;
}
}
return Colors.white;
}
}