feat: add force flag to emit in Bloc and Cubit - #4862
Open
OmarAly92 wants to merge 1 commit into
Open
Conversation
Adds an optional `force` parameter (defaults to `false`) to `emit` so a
state can be emitted even when it is equal to the current state.
- `Emittable.emit`, `BlocBase.emit` and `Bloc.emit` accept `{bool force = false}`
- `Emitter.call` forwards `force`, so `emit(state, force: true)` works
inside event handlers and still triggers `onTransition`/`onChange`
- `ReplayCubitMixin.emit` and `ReplayBlocMixin.emit` forward `force`
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sy5uFShMuySLy6T8kGaXor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
READY
Breaking Changes
NO
Description
This PR adds a
forceparameter to theemit()method across the bloc library, allowing developers to emit duplicate states (states equal to the current state) when needed.Changes
BlocBase: Added optionalforceparameter toemit(). Whenforce: true, the state is emitted even if it equals the current state, triggeringonChangecallbacks and notifying listeners.Bloc: Updated theemit()override to accept and forward theforceparameter. Modified the internalonEmitcallback in event handlers to respect theforceflag.Emitter: Addedforceparameter to thecall()method and the_Emitterimplementation to support forced emissions in event handlers.ReplayBlocMixin&ReplayCubitMixin: Updated to forward theforceparameter through the replay stack operations.onChangecallbacks and emit duplicate statesonTransitioncallbacksUse Case
This feature enables scenarios where developers need to re-emit the current state to trigger listeners or observers, which is useful for state refresh operations or explicit state notifications.