-
BehaviorSubject close 이슈 Bad state: Cannot add new events after calling closeflutter 2022. 5. 13. 00:38
Bad state: Cannot add new events after calling close 관련
BehaviorSubject close 하면 객체가 폐기된다.
그래서 다음에 또 사용하려면 이벤트 추가를 할수가없음
그래서 참조값을 late 로 선언만 해놓고
사용하는 페이지에서 초기화해주고, dispose에서 close해주는게 좋다.
class MyBloc { final _data = BehaviorSubject<String>(); void fetchData() { // get your data from wherever it is located _data.safeValue = 'Safe to add data'; } void dispose() { _data.close(); } }
-> MyBloc 사용할때 초기화되고, 페이지 떠나면 close, 다시 사용할때 초기화되고, 페이지 떠나면 close
flutter: Unhandled Exception: Bad state: Cannot add new events after calling close
I am trying to use the bloc pattern to manage data from an API and show them in my widget. I am able to fetch data from API and process it and show it, but I am using a bottom navigation bar and wh...
stackoverflow.com
https://github.com/felangel/bloc/issues/120
Bad state: Cannot add new events after calling close after the bloc is disposed. · Issue #120 · felangel/bloc
I got this error while trying a scenario: I need to fetch some data from the API. To simulate the fetching delay time, i use await Future.delayed(Duration(seconds: 2)); in the mapEventToState bloc....
github.com
https://github.com/felangel/bloc/issues/52
Bad state: Cannot add new events after calling close · Issue #52 · felangel/bloc
I can't trace the issue on my code, not sure it's my code problem or the library StateError: Bad state: Cannot add new events after calling close File "broadcast_stream_controller.dart...
github.com
'flutter' 카테고리의 다른 글
disposable class (0) 2022.10.23 FirebaseAuth.instance.authStateChanges (1) 2022.09.21 bloc 7.2버전부터 바뀐 이벤트 처리 (0) 2021.12.10 [메모/스크랩] map 함수 (0) 2021.12.10 copyWith 함수 (0) 2021.12.07