fluffychat/lib/utils/string_color.dart

35 lines
862 B
Dart
Raw Normal View History

2020-01-18 12:22:22 +00:00
import 'package:flutter/material.dart';
extension StringColor on String {
2022-08-08 06:31:12 +00:00
static final _colorCache = <String, Map<double, Color>>{};
Color _getColorLight(double light) {
2020-06-25 07:15:53 +00:00
var number = 0.0;
for (var i = 0; i < length; i++) {
number += codeUnitAt(i);
}
2021-07-31 18:12:18 +00:00
number = (number % 12) * 25.5;
2022-08-08 06:31:12 +00:00
return HSLColor.fromAHSL(1, number, 1, light).toColor();
}
Color get color {
_colorCache[this] ??= {};
return _colorCache[this]![0.35] ??= _getColorLight(0.35);
2020-06-25 07:15:53 +00:00
}
2021-01-16 20:50:01 +00:00
Color get darkColor {
2022-08-08 06:31:12 +00:00
_colorCache[this] ??= {};
return _colorCache[this]![0.2] ??= _getColorLight(0.2);
2021-01-16 20:50:01 +00:00
}
2023-01-29 15:29:25 +00:00
Color get lightColorText {
2022-08-08 06:31:12 +00:00
_colorCache[this] ??= {};
return _colorCache[this]![0.7] ??= _getColorLight(0.7);
2020-01-18 12:22:22 +00:00
}
2023-01-29 15:29:25 +00:00
Color get lightColorAvatar {
_colorCache[this] ??= {};
return _colorCache[this]![0.4] ??= _getColorLight(0.4);
}
2020-01-18 12:22:22 +00:00
}