flutter_client_sse
flutter_client_sse copied to clipboard
When unsubscribe From SSE the _retryConnection method must stop
The error you are encountering occurs because you are attempting to add events to a StreamController that has already been closed. This issue is happening because unsubscribeFromSSE() closes the _streamController, but the SSEClient continues to try to add events to it.
Steps to Resolve the Issue
Check if the StreamController is Closed Before Adding Events: You can modify the code to check if the _streamController is closed before adding events. This will prevent the "Bad state: Cannot add new events after calling close" error.
Properly Handle the Stream Lifecycle:
Ensure that when you unsubscribe from SSE, no new events are being processed or added to the stream. After calling unsubscribeFromSSE(), you should stop any further attempts to subscribe to or retry the SSE connection.