rrousselGit/freezed

Add option to include getters in toString() and exclude parameters

オープン

#698 opened on 2022/07/06

 (1 件のコメント) (0 件のリアクション) (1 人の担当者)Dart (300 件のフォーク)github user discovery
enhancementgood first issue

Repository metrics

Stars
 (2,177 個のスター)
PR merge metrics
 (平均マージ 25d 18h) (30d で 1 merged PR)

説明

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;
}

コントリビューターガイド