- Added `Color().luminance` extension (thanks @rania-run)
- Fixed a bug in `String.splitByLength()`

Signed-off-by: Hans Kokx <hans.kokx@hackberry.se>
This commit is contained in:
Hans Kokx
2024-10-29 11:34:10 +01:00
parent adb4217c35
commit 15f831f1dd
6 changed files with 47 additions and 3 deletions
+14
View File
@@ -0,0 +1,14 @@
import "package:pure_dart_ui/pure_dart_ui.dart";
/// A collection of extensions for the `Color` class.
extension ColorsExtensions on Color {
/// Determines if the color is considered dark.
///
/// A color is considered dark if its luminance is less than 0.5.
bool get isDark {
final luminance = computeLuminance();
// Luminance values range from 0 to 1, where 0 is black and 1 is white.
// A luminance value below 0.5 indicates a dark color.
return luminance < 0.5;
}
}
+7 -2
View File
@@ -63,8 +63,13 @@ extension Split on String {
String string = this;
while (string.isNotEmpty) {
parts.add(string.substring(0, length));
string = string.substring(length);
if (string.length >= length) {
parts.add(string.substring(0, length));
string = string.substring(length);
} else {
parts.add(string.substring(0, string.length));
string = string.substring(string.length);
}
}
return parts;
}