- Added `printValue()` method as an extension to `dynamic`

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2025-01-16 11:07:19 +01:00
parent 92f475a8c7
commit b066eace19
5 changed files with 70 additions and 4 deletions
+1
View File
@@ -1,6 +1,7 @@
library arcane_helper_utils;
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/string.dart";
export "package:arcane_helper_utils/src/extensions/string_jwt.dart";
+40
View File
@@ -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;
}
}