mnemo_cards/lib/utils/string_helper.dart
2024-05-22 23:48:44 +03:00

24 lines
618 B
Dart

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;
}
}