25 lines
618 B
Dart
25 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;
|
||
|
|
}
|
||
|
|
}
|