COMPACT property
Compact format: parameter names excluded, single-line format.
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
static final COMPACT = ToStringOptions(includeParameterNames: false);