Skip to content

fix: emitting a state in a closed Cubit throws an error #4165

Closed
@ra48ad

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

  1. Create a new Cubit
  2. Add an async function that waits for 5 seconds, then emits a new state.
  3. Create a new instance of this Cubit in your main method and call the function in 2) and then close the Cubit.
  4. 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

Metadata

Assignees

Labels

discussionOpen discussion for a specific topicpkg:blocThis issue is related to the bloc package

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions