About StateError (Bad state: Cannot add new events after calling close) problem
Closed this issue · 2 comments
Hi,
When I follow these steps, I get the error that in the title;
1- I added the following code to the onpressed event of the login button on the
Search page;
commonBloc.add(constForceLogoutButtonPressed());
2- I ran the application, came to the search page and clicked the login button. The application was redirected to the login page.
3-I tried to login by entering random user information on the login page and got the following error;
@bedirhanayydin When you execute any UseCases like ClearCurrentUserDataUseCase
, we dispatch two events to show and hide the CircularProgressIndicator
are LoadingVisibilityEmitted(isLoading: true)
and LoadingVisibilityEmitted(isLoading: false)
. After you logged in successfully, the Login screen may be popped or be replaced, so it can not add the event LoadingVisibilityEmitted(isLoading: false)
to hide CircularProgressIndicator
. That's why you got that error. In short, you should not add any events after the screen was popped. To avoid this error, I overrided add
method of Bloc in this PR (https://github.com/ntminhdn/Flutter-Bloc-CleanArchitecture/pull/5/files). And now, you only get an error log instead of an error.
In this PR, I improved the log. Now, we can check the log about navigation events and all bloc events. It helps you to check the reason for that error easily.
I understand. Thank you for your support.