[Flutter] Freezed Error

김동욱·2024년 2월 2일
0

Freezed Error 로 추정

E/flutter (12521): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: Cannot add to an unmodifiable list
E/flutter (12521): #0 UnmodifiableListMixin.add (dart:_internal/list.dart:114:5)
E/flutter (12521): #1 RouletteViewModel.drawPokemon (package:pokedex_clean/presentation/main/roulette/roulette_view_model.dart:33:23)
E/flutter (12521): #2 _RouletteScreenState.build. (package:pokedex_clean/presentation/main/roulette/roulette_screen.dart:116:35)
E/flutter (12521): #3 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:275:24)
E/flutter (12521): #4 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:652:11)
E/flutter (12521): #5 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:309:5)
E/flutter (12521): #6 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:242:7)
E/flutter (12521): #7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:630:9)
E/flutter (12521): #8 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:98:12)
E/flutter (12521): #9 PointerRouter._dispatchEventToRoutes. (package:flutter/src/gestures/pointer_router.dart:143:9)
E/flutter (12521): #10 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
E/flutter (12521): #11 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
E/flutter (12521): #12 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:127:7)
E/flutter (12521): #13 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:488:19)
E/flutter (12521): #14 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:468:22)
E/flutter (12521): #15 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:439:11)
E/flutter (12521): #16 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:413:7)

원인

freezed 로 선언된 변수는 modify 가 기본임
해당 리스트를 수정하기 위해 List.from 함수를 통해서 terable에서 요소를 사용하여 새로운 List를 생성 후 state 에 copywith 로 변경

해결완료

profile
백엔드 개발자

0개의 댓글