mirror of
https://github.com/hanskokx/arcane_helper_utils.git
synced 2026-05-14 10:29:07 +02:00
v1.2.6
- Added `printValue()` method as an extension to `dynamic` Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -1,3 +1,19 @@
|
|||||||
|
## 1.2.6
|
||||||
|
|
||||||
|
- Added the `printValue()` extension.
|
||||||
|
The `printValue()` extension can be used to print a value to the console
|
||||||
|
before returning that same value.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```dart
|
||||||
|
// Print the `textTheme` object to the console before returning it
|
||||||
|
Text(
|
||||||
|
'Hello, world',
|
||||||
|
style: Theme.of(context).textTheme.printValue().headlineMedium,
|
||||||
|
),
|
||||||
|
```
|
||||||
|
|
||||||
## 1.2.5
|
## 1.2.5
|
||||||
|
|
||||||
- Null `String`s being manipulated should return `null` instead of an empty `String`
|
- Null `String`s being manipulated should return `null` instead of an empty `String`
|
||||||
|
|||||||
+12
-3
@@ -36,17 +36,17 @@ void main() {
|
|||||||
|
|
||||||
// Capitalize a string
|
// Capitalize a string
|
||||||
const String lowercase = "hello";
|
const String lowercase = "hello";
|
||||||
final String capitalized = lowercase.capitalize;
|
final String capitalized = lowercase.capitalize!;
|
||||||
print(capitalized); // "Hello"
|
print(capitalized); // "Hello"
|
||||||
|
|
||||||
// Capitalize words in a string
|
// Capitalize words in a string
|
||||||
const String lowercaseWords = "hello world";
|
const String lowercaseWords = "hello world";
|
||||||
final String capitalizedWords = lowercaseWords.capitalizeWords;
|
final String capitalizedWords = lowercaseWords.capitalizeWords!;
|
||||||
print(capitalizedWords); // "Hello World"
|
print(capitalizedWords); // "Hello World"
|
||||||
|
|
||||||
// Space out PascalCase words
|
// Space out PascalCase words
|
||||||
const String pascalCase = "ArcaneHelperUtils";
|
const String pascalCase = "ArcaneHelperUtils";
|
||||||
final String spacedOut = pascalCase.spacePascalCase;
|
final String spacedOut = pascalCase.spacePascalCase!;
|
||||||
print(spacedOut); // "Arcane Helper Utils";
|
print(spacedOut); // "Arcane Helper Utils";
|
||||||
|
|
||||||
// * Lists
|
// * Lists
|
||||||
@@ -67,6 +67,15 @@ void main() {
|
|||||||
// Process the existing list, in place
|
// Process the existing list, in place
|
||||||
people.unique((person) => person.id);
|
people.unique((person) => person.id);
|
||||||
print(people.map((p) => p.name)); // Output: ['Alice', 'Bob']
|
print(people.map((p) => p.name)); // Output: ['Alice', 'Bob']
|
||||||
|
|
||||||
|
// * Dynamic debug printing
|
||||||
|
// Debug print the `Person` object before returning the name
|
||||||
|
final String alice = const Person(id: 0, name: "Alice").printValue<Person>().name;
|
||||||
|
print(alice); // Output: 'Alice'
|
||||||
|
|
||||||
|
// Debug print the `Person` object with a label before returning the name
|
||||||
|
final String bob = const Person(id: 1, name: "Bob").printValue<Person>("Person").name;
|
||||||
|
print(bob); // Output: 'Bob'
|
||||||
}
|
}
|
||||||
|
|
||||||
class Person {
|
class Person {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
library arcane_helper_utils;
|
library arcane_helper_utils;
|
||||||
|
|
||||||
export "package:arcane_helper_utils/src/extensions/date_time.dart";
|
export "package:arcane_helper_utils/src/extensions/date_time.dart";
|
||||||
|
export "package:arcane_helper_utils/src/extensions/dynamic.dart";
|
||||||
export "package:arcane_helper_utils/src/extensions/list.dart";
|
export "package:arcane_helper_utils/src/extensions/list.dart";
|
||||||
export "package:arcane_helper_utils/src/extensions/string.dart";
|
export "package:arcane_helper_utils/src/extensions/string.dart";
|
||||||
export "package:arcane_helper_utils/src/extensions/string_jwt.dart";
|
export "package:arcane_helper_utils/src/extensions/string_jwt.dart";
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
// ignore_for_file: avoid_print
|
||||||
|
|
||||||
|
extension DynamicPrintExtension on dynamic {
|
||||||
|
/// The `printValue()` extension can be used to print a value to the
|
||||||
|
/// console before returning that same value.
|
||||||
|
///
|
||||||
|
/// Example:
|
||||||
|
/// ```dart
|
||||||
|
/// Text(
|
||||||
|
/// 'Hello, world',
|
||||||
|
/// style: Theme.of(context).textTheme.printValue().headlineMedium,
|
||||||
|
/// ),
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// This will print the text style to the console before returning it, which
|
||||||
|
/// can be useful for debugging.
|
||||||
|
///
|
||||||
|
/// Additionally, an optional label can be specified for the printed value, which
|
||||||
|
/// will be prepended to the output.
|
||||||
|
/// ```dart
|
||||||
|
/// Text(
|
||||||
|
/// 'Hello, world',
|
||||||
|
/// style: Theme.of(context).textTheme.printValue('headlineMedium'),
|
||||||
|
/// ),
|
||||||
|
/// ```
|
||||||
|
@Deprecated(
|
||||||
|
"WARNING: The printValue() extension can potentially leak sensitive "
|
||||||
|
"information.\n"
|
||||||
|
"It is recommended to use only during debugging and to remove before "
|
||||||
|
"releasing to production.",
|
||||||
|
)
|
||||||
|
T printValue<T>([String label = ""]) {
|
||||||
|
if (label.isNotEmpty) {
|
||||||
|
print("$label: ${toString()}");
|
||||||
|
} else {
|
||||||
|
print("${toString()}");
|
||||||
|
}
|
||||||
|
return this as T;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -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.2.5
|
version: 1.2.6
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user