flutter-freaccess-hub/lib/shared/extensions/string_extensions.dart

42 lines
913 B
Dart

import 'dart:ui';
extension StringNullableExtensions on String? {
bool get toBoolean {
if (this == null) return false;
return this!.toLowerCase() == 'true';
}
bool get isNullOrEmpty {
if (this == null) return true;
if (this == '') return true;
return false;
}
bool get isNotNullAndEmpty {
if (this == null) return false;
if (this == '') return false;
return true;
}
}
extension StringExtensions on String {
bool get toBoolean {
return toLowerCase() == 'true';
}
}
extension StringExtension on String? {}
extension HexColor on String {
Color toColor() {
final hexCode = replaceAll('#', '');
final buffer = StringBuffer();
if (hexCode.length == 6) {
buffer
.write('ff'); // Adiciona opacidade total caso não esteja especificada
}
buffer.write(hexCode);
return Color(int.parse(buffer.toString(), radix: 16));
}
}