1.0.0
Some checks failed
Code Coverage / upload (push) Has been cancelled
Gh-Pages / build (push) Has been cancelled
Code Verification / verify (push) Has been cancelled

This commit is contained in:
zypherift
2025-08-09 18:17:34 +02:00
commit c7e3f36b06
438 changed files with 79192 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import 'dart:ui';
extension ColorExtension on Color {
/// Convert the color to a darken color based on the [percent]
Color darken([int percent = 40]) {
assert(1 <= percent && percent <= 100);
final value = 1 - percent / 100;
return Color.fromARGB(
_floatToInt8(a),
(_floatToInt8(r) * value).round(),
(_floatToInt8(g) * value).round(),
(_floatToInt8(b) * value).round(),
);
}
Color lighten([int percent = 40]) {
assert(1 <= percent && percent <= 100);
final value = percent / 100;
return Color.fromARGB(
_floatToInt8(a),
(_floatToInt8(r) + ((255 - _floatToInt8(r)) * value)).round(),
(_floatToInt8(g) + ((255 - _floatToInt8(g)) * value)).round(),
(_floatToInt8(b) + ((255 - _floatToInt8(b)) * value)).round(),
);
}
Color avg(Color other) {
final red = (_floatToInt8(r) + _floatToInt8(other.r)) ~/ 2;
final green = (_floatToInt8(g) + _floatToInt8(other.g)) ~/ 2;
final blue = (_floatToInt8(b) + _floatToInt8(other.b)) ~/ 2;
final alpha = (_floatToInt8(a) + _floatToInt8(other.a)) ~/ 2;
return Color.fromARGB(alpha, red, green, blue);
}
// Int color components were deprecated in Flutter 3.27.0.
// This method is used to convert the new double color components to the
// old int color components.
//
// Taken from the Color class.
int _floatToInt8(double x) {
return (x * 255.0).round() & 0xff;
}
}

View File

@@ -0,0 +1,3 @@
extension IterableToMapExtension<K, V> on Iterable<MapEntry<K, V>> {
Map<K, V> get asMap => Map.fromEntries(this);
}

View File

@@ -0,0 +1,3 @@
extension ListToMapExtension<K, V> on List<MapEntry<K, V>> {
Map<K, V> get asMap => Map.fromEntries(this);
}