- 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
+12 -3
View File
@@ -36,17 +36,17 @@ void main() {
// Capitalize a string
const String lowercase = "hello";
final String capitalized = lowercase.capitalize;
final String capitalized = lowercase.capitalize!;
print(capitalized); // "Hello"
// Capitalize words in a string
const String lowercaseWords = "hello world";
final String capitalizedWords = lowercaseWords.capitalizeWords;
final String capitalizedWords = lowercaseWords.capitalizeWords!;
print(capitalizedWords); // "Hello World"
// Space out PascalCase words
const String pascalCase = "ArcaneHelperUtils";
final String spacedOut = pascalCase.spacePascalCase;
final String spacedOut = pascalCase.spacePascalCase!;
print(spacedOut); // "Arcane Helper Utils";
// * Lists
@@ -67,6 +67,15 @@ void main() {
// Process the existing list, in place
people.unique((person) => person.id);
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 {