[DEV] Added infrastructure extension exports
This commit is contained in:
19
lib/Infrastructure/string_extensions.dart
Normal file
19
lib/Infrastructure/string_extensions.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user