fix: emitting a state in a closed Cubit throws an error #4165
Closed
Description
Description
Trying to emit a state when the cubit is closed (can happen for example in async functions) leads to an Error being thrown. This behaviour may be intentional, but it is - however - different from a Bloc's behaviour the emit is called.
Steps To Reproduce
- Create a new Cubit
- Add an async function that waits for 5 seconds, then emits a new state.
- Create a new instance of this Cubit in your main method and call the function in 2) and then close the Cubit.
- You should get an Error thrown that says "Cannot emit new states after calling close"
Expected Behavior
Calling emit on a closed Cubit ignores the new state and throws no error (Just like a Bloc would)
Screenshots
Additional Context