LateInitializationError

Baek Dong Hyun·2023년 2월 23일
0

이전 글에서 작성했는데 짱구 mbti 프로젝트를 작업하던 도중 에러가 발생했다.
이 에러는 처음 테스트를 할땐 나오지 않다가 홈으로 가기 버튼을 누른 후 다시 테스트를 진행하고, 결과페이지로 이동하게되면 나타나던 에러이다.
열심히 검색하고 이 방법, 저 방법 삽질을 했는데 그 과정중에

https://stackoverflow.com/questions/67040839/flutter-lateinitializationerror-field-name-has-not-been-initialized

I had the same problem of lateInitializationError I find out to use ? to avoid it. if some one is facing this problem instead of late try ?.
저는 lateInitializationError와 동일한 문제를 가지고 있었습니다. 이 문제를 피하기 위해 ?를 사용했습니다. 만약 누군가가 늦은 시도 대신 이 문제에 직면한다면 ?

stackoverflow에서 위 글을 보았고, null 문제인가싶어 해당 코드를 조금 수정했었다.

_resultDetail = _resultListModel.resultList.firstWhere((e) => e.type == mbti);

위 코드를 아래로

_resultDetail = _resultListModel.resultList.firstWhereOrNull((e) => e.type == mbti)!;

수정했더니 똑같은 에러가 발생했다. 그 후 다시 검색해본 결과

https://velog.io/@baekmoon1230/LateInitializationError-Field-%EB%B3%80%EC%88%98%EB%AA%85-has-not-been-initialized

https://www.fluttercampus.com/guide/241/lateinitializatioerror-field-has-not-been-initialized-error/

이 블로그 글들을 보게 됐고, 초기값을 지정해줘야될거같아 코드를 다시 수정해보았다.

late final ResultDetail _resultDetail;

위 코드를 아래 코드로

late ResultDetail _resultDetail = ResultDetail(type: '', detail: ResultContent(name: '', contents: '', path: ''));

수정 해보니 에러 없이 잘 구동되었다.

profile
안녕하세요.

0개의 댓글