rrousselGit/freezed
Add option to include getters in toString() and exclude parameters
Offen
#698 geöffnet am 06.07.2022
enhancementgood first issue
Repository-Metriken
- Stars
- (2.177 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 25T 18h) (1 gemergte PR in 30 T)
Beschreibung
Is your feature request related to a problem? Please describe.
Sometimes it's helpful for debugging to have the result of some getters in the toString() method.
Describe the solution you'd like
// until now
@freezed
class MyClass with _$MyClass {
const factory MyClass({
required int a,
required int b,
}) = _MyClass;
const MyClass._();
int get sum => a + b;
}
MyClass(a: 40, b: 2).toString(); // => 'MyClass(a: 40, b: 2)'
// expected
MyClass(a: 40, b: 2).toString(); // => 'MyClass(a: 40, b: 2, sum: 42)'
// could be achieved by annotating the whole class or a single getter
@Freezed(toStringWithGetters: true)
class MyClass with _$MyClass {
const factory MyClass({
required int a,
required int b,
}) = _MyClass;
const MyClass._();
int get sum => a + b;
}
// or
@freezed
class MyClass with _$MyClass {
const factory MyClass({
required int a,
required int b,
}) = _MyClass;
const MyClass._();
@addToString
int get sum => a + b;
}