-
setState() called after dispose() 오류flutter 2021. 4. 21. 01:55
setState() called after dispose(): _CommunotyReaderScreenState#a45bb(lifecycle state: defunct, not mounted)
I/flutter (31938): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
I/flutter (31938): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
I/flutter (31938): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
위젯트리에 객체가 없는데 그것의 상태를 setstate 로 변경하려고 할때 나는 오류..
나의경우 stateful 위젯의 initState 에 특정 초기화 함수를 넣어놨는데..그함수에서 setstate를 실행함..
여러가지 이유로 화면을 전환하다보면, mounted가 되지 않은 상태인데도 setstate를 실행할때 오류가 발생함
해당 내용을 mounted 됐을때만 setstate 하도록 바꿔주면 해결됨
'flutter' 카테고리의 다른 글
flutter bloc 패턴, rxdart.. (0) 2021.07.03 TabBarView PageView에서 위젯 리빌드 방지 (0) 2021.05.03 null safety (0) 2021.05.02 플러터 라이프 사이클 (0) 2021.04.21 runtransaction 트랜잭션 처리 (0) 2021.04.21