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:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user