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:
@@ -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
|
||||
|
||||
- [BREAKING] Removed `Unfocuser` widget to ensure pure Dart compatibility.
|
||||
|
||||
@@ -15,6 +15,7 @@ providing utility functions and extensions that simplify common tasks.
|
||||
class, making it easier to format dates and calculate differences.
|
||||
- **String Extensions**: Enhances the `String` class by adding new methods for
|
||||
common transformations and checks, including JWT parsing.
|
||||
- **Color Extensions**: Adds the ability to determine the luminance of a `Color`
|
||||
|
||||
## Getting Started
|
||||
|
||||
@@ -330,6 +331,16 @@ objects:
|
||||
Additionally, the `CommonString` class provides a quick shortcut to common
|
||||
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
|
||||
|
||||
Contributions are welcome! Feel free to fork the repository and submit pull
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
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() {
|
||||
// DateTime
|
||||
@@ -33,4 +35,10 @@ void main() {
|
||||
const String lowercase = "hello";
|
||||
final String capitalized = lowercase.capitalize;
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
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;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
name: arcane_helper_utils
|
||||
description: Provides a variety of helpful utilities and extensions for Flutter
|
||||
and Dart.
|
||||
version: 1.1.0
|
||||
version: 1.1.1
|
||||
repository: https://github.com/hanskokx/arcane_helper_utils
|
||||
issue_tracker: https://github.com/hanskokx/arcane_helper_utils/issues
|
||||
|
||||
@@ -15,6 +15,7 @@ environment:
|
||||
|
||||
dependencies:
|
||||
freezed_annotation: ^2.4.4
|
||||
pure_dart_ui: ^0.1.10
|
||||
week_number: ^1.1.0
|
||||
|
||||
dev_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user