mirror of
https://github.com/hanskokx/arcane_helper_utils.git
synced 2026-05-14 02:19:09 +02:00
v1.1.1
- 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:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user