diff --git a/lib/src/colorized_text_avatar.dart b/lib/src/colorized_text_avatar.dart index 461a908..4291bc8 100644 --- a/lib/src/colorized_text_avatar.dart +++ b/lib/src/colorized_text_avatar.dart @@ -34,19 +34,33 @@ class TextAvatar extends StatelessWidget { Widget build(BuildContext context) { shape = (shape == null) ? Shape.Rectangle : shape; size = (size == null || size! < 32.0) ? 48.0 : size; - backgroundColor = backgroundColor == null ? _colorBackgroundConfig() : backgroundColor; + backgroundColor = + backgroundColor == null ? _colorBackgroundConfig() : backgroundColor; textColor = _colorTextConfig(); return _textDisplay(); } Color _colorBackgroundConfig() { - if (RegExp(r'[A-Z]|').hasMatch( - _textConfiguration(), - )) { - backgroundColor = - colorData[_textConfiguration()[0].toLowerCase().toString()]; + Color? color = colorData[_textConfiguration()[0].toLowerCase().toString()]; + if (color == null) { + color = buildBackgroundColor(); } - return backgroundColor!; + + return color; + } + + Color buildBackgroundColor() { + String newText = text == null ? '?' : _toString(value: text); + String hexCode = newText + .toString() + .codeUnits + .map((e) => e.toRadixString(16)) + .join() + .toUpperCase(); + + String color = 'FF${hexCode.substring(0, 6)}'; + + return Color(int.parse(color, radix: 16)); } Color _colorTextConfig() { diff --git a/lib/src/constants/colors.dart b/lib/src/constants/colors.dart index f420f57..3f9bf84 100644 --- a/lib/src/constants/colors.dart +++ b/lib/src/constants/colors.dart @@ -26,5 +26,14 @@ var colorData = { "w": Color.fromRGBO(194, 194, 194, 1), "x": Color.fromRGBO(124, 222, 235, 1), "y": Color.fromRGBO(188, 170, 164, 1), - "z": Color.fromRGBO(173, 214, 125, 1), + "1": Color.fromRGBO(229, 115, 115, 1), + "2": Color.fromRGBO(67, 160, 71, 1), + "3": Color.fromRGBO(255, 179, 0, 1), + "4": Color.fromRGBO(244, 81, 30, 1), + "5": Color.fromRGBO(228, 72, 215, 1), + "6": Color.fromRGBO(255, 110, 64, 1), + "7": Color.fromRGBO(0, 121, 107, 1), + "8": Color.fromRGBO(158, 158, 158, 1), + "9": Color.fromRGBO(106, 27, 154, 1), + "0": Color.fromRGBO(226, 82, 97, 1), };