본문 바로가기
개발/Flutter

freezed 에서 custom method, add method 새로운 함수 만들기

by dev_caleb 2022. 11. 20.
728x90

나는 freezed Model에 해당과 같이 넣고 싶다.

String toNotiString() {
  List result = [];
  if (xp != null) {
    result.add('xp:$xp');
  }
  if (gold != null) {
    result.add('gold:$gold');
  }
  if (diamond != null) {
    result.add('diamond:$diamond');
  }
  return result.join(', ');
}

그런데 오류가 나지.. 

 

해결책은 doc에 있었다.

https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models

 

GitHub - rrousselGit/freezed: Code generation for immutable classes that has a simple syntax/API without compromising on the fea

Code generation for immutable classes that has a simple syntax/API without compromising on the features. - GitHub - rrousselGit/freezed: Code generation for immutable classes that has a simple synt...

github.com

Wow..

728x90