Files
astromic_elements/lib/Infrastructure/string_extensions.dart

20 lines
655 B
Dart

import 'package:flutter/material.dart';
extension StringExtensions on String {
/// Parse the HexCode to color
Color get toColor {
if (this == '') return const Color(0xFF000000);
String hexColor = replaceAll('#', '');
hexColor = hexColor.replaceAll('0x', '');
hexColor = hexColor.padLeft(6, '0');
hexColor = hexColor.padLeft(8, 'F');
final int length = hexColor.length;
return Color(int.tryParse('0x${hexColor.substring(length - 8, length)}') ?? 0xFF000000);
}
/// Capitalize the first letter in a string.
String get capitalize {
return (length > 1) ? this[0].toUpperCase() + substring(1) : toUpperCase();
}
}