first commit
This commit is contained in:
31
lib/components/extensions/string.dart
Normal file
31
lib/components/extensions/string.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
// Flutter imports:
|
||||
import 'package:flutter/material.dart' show Color;
|
||||
|
||||
///
|
||||
/// Расширение для работы со строками
|
||||
///
|
||||
extension MString on String {
|
||||
///
|
||||
/// Слово с заглавной буквы
|
||||
///
|
||||
String capitalyze() {
|
||||
final String str = toLowerCase();
|
||||
final String first = str.substring(0, 1);
|
||||
|
||||
return '${first.toUpperCase()}${str.substring(1)}';
|
||||
}
|
||||
|
||||
///
|
||||
/// Парсинг hex string в color
|
||||
///
|
||||
Color get toColor {
|
||||
String res = replaceFirst('#', '');
|
||||
|
||||
return Color(
|
||||
int.parse(
|
||||
res.length == 8 ? res : (res.length == 6 ? 'FF$res' : res),
|
||||
radix: 16,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user