- 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
+5
View File
@@ -1,3 +1,8 @@
## 1.1.1
- Added `Color` extension for luminance. Thanks, @rania-run!
- Fixed a bug in the `splitByLength` extension on `String`
## 1.1.0 ## 1.1.0
- [BREAKING] Removed `Unfocuser` widget to ensure pure Dart compatibility. - [BREAKING] Removed `Unfocuser` widget to ensure pure Dart compatibility.
+11
View File
@@ -15,6 +15,7 @@ providing utility functions and extensions that simplify common tasks.
class, making it easier to format dates and calculate differences. class, making it easier to format dates and calculate differences.
- **String Extensions**: Enhances the `String` class by adding new methods for - **String Extensions**: Enhances the `String` class by adding new methods for
common transformations and checks, including JWT parsing. common transformations and checks, including JWT parsing.
- **Color Extensions**: Adds the ability to determine the luminance of a `Color`
## Getting Started ## Getting Started
@@ -330,6 +331,16 @@ objects:
Additionally, the `CommonString` class provides a quick shortcut to common Additionally, the `CommonString` class provides a quick shortcut to common
strings, such as punctuation marks that are otherwise cumbersome to find or type. strings, such as punctuation marks that are otherwise cumbersome to find or type.
### Color Examples
The following utilities have been added to enhance working with `Color` objects:
- `luminance`: Computes the luminance of a given color.
```dart
final Color luminanceBasedColor = myColor.isDark ? Colors.white : Colors.black;
```
## Contributing ## Contributing
Contributions are welcome! Feel free to fork the repository and submit pull Contributions are welcome! Feel free to fork the repository and submit pull
+8
View File
@@ -1,4 +1,6 @@
import "package:arcane_helper_utils/arcane_helper_utils.dart"; import "package:arcane_helper_utils/arcane_helper_utils.dart";
import "package:arcane_helper_utils/src/extensions/color.dart";
import "package:pure_dart_ui/pure_dart_ui.dart";
void main() { void main() {
// DateTime // DateTime
@@ -33,4 +35,10 @@ void main() {
const String lowercase = "hello"; const String lowercase = "hello";
final String capitalized = lowercase.capitalize; final String capitalized = lowercase.capitalize;
print(capitalized); // "Hello" print(capitalized); // "Hello"
// Color
const Color myColor = Color.fromARGB(255, 153, 97, 227);
final Color luminanceBasedcolor =
myColor.isDark ? const Color(0xff000000) : const Color(0xffffffff);
print(luminanceBasedcolor); // Color(0xff000000)
} }
+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; String string = this;
while (string.isNotEmpty) { while (string.isNotEmpty) {
parts.add(string.substring(0, length)); if (string.length >= length) {
string = string.substring(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; return parts;
} }
+2 -1
View File
@@ -1,7 +1,7 @@
name: arcane_helper_utils name: arcane_helper_utils
description: Provides a variety of helpful utilities and extensions for Flutter description: Provides a variety of helpful utilities and extensions for Flutter
and Dart. and Dart.
version: 1.1.0 version: 1.1.1
repository: https://github.com/hanskokx/arcane_helper_utils repository: https://github.com/hanskokx/arcane_helper_utils
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
@@ -15,6 +15,7 @@ environment:
dependencies: dependencies:
freezed_annotation: ^2.4.4 freezed_annotation: ^2.4.4
pure_dart_ui: ^0.1.10
week_number: ^1.1.0 week_number: ^1.1.0
dev_dependencies: dev_dependencies: