ToStringOptions constructor
ToStringOptions({})
Configuration options for customizing toString output in JetLeaf objects.
Used together with EqualsAndHashCode and the equalizer utility to control
how objects are represented as strings. This allows fine-grained control over:
- Parameter naming (automatic, type-based, or custom)
- Multi-line vs compact formatting
- Inclusion/exclusion of class names
- Custom separators
Predefined Formats
- STANDARD →
User(id: 1, name: Alice) - COMPACT →
User(1, Alice) - MULTILINE →
User( id: 1, name: Alice ) - COMPACT_MULTILINE →
User( 1, Alice ) - SMART_NAMES → infers names based on values (e.g.,
"email","age") - TYPE_BASED_NAMES → uses runtime types (e.g.,
"string","int")
Example
class User implements EqualsAndHashCode {
final String id;
final String name;
User(this.id, this.name);
@override
List<Object?> equalizedProperties() => [id, name];
}
void main() {
final user = User('1', 'Alice');
print(equalizer.toString(user, ToStringOptions.STANDARD));
// => User(id: 1, name: Alice)
print(equalizer.toString(user, ToStringOptions.COMPACT));
// => User(1, Alice)
}
Implementation
ToStringOptions({
this.includeParameterNames = true,
this.useNewlines = false,
this.customSeparator,
this.includeClassName = true,
this.customParameterNames,
this.customParameterNameGenerator,
});