728x90
freezed 를 사용하고 있는데 변수명 다를 때랑 초기값 지정이 좀 고민이었다.
Using Flutter Freezed to generate code to parse a Json Object
I'm trying to parse some JSON from a file and decided to use Freezed to generate the code. The problem is that (as far as i can tell) there's no way to use a JSON object's name. So say I have the
stackoverflow.com
이걸 보고 문제 해결!
이런 식으로 anootation을 달아준다. Default는 초기값, JsonKey-name은 키 값 다를 때, Default를 넣어줄 때 required를 같이 쓰면 오류가 나니 주의!
@Default([]) @JsonKey(name: 'other-links') List<OtherLink> otherLinks,

728x90
'개발 > Flutter' 카테고리의 다른 글
sliver_tool 사용해 보기 (0) | 2022.12.02 |
---|---|
How to save Color data in flutter (0) | 2022.12.01 |
flutter how to know recent version (0) | 2022.11.26 |
Flutter hive 원하는 model 넣기 (0) | 2022.11.25 |
flutter hive unknown type error (2) | 2022.11.25 |