Bloc Builder
A composable that subscribes to a StateEmitter's state stream and passes the current state to content on every emission.
Use BlocBuilder as a concise way to bind bloc state to UI. To restrict rebuilds to specific transitions, use the buildWhen overload instead.
Usage
val bloc = remember { BlocRegistry.resolve(CounterBloc::class) }
BlocBuilder(bloc) { state ->
Text("Count: ${state.count}")
Button(onClick = { bloc.add(CounterEvent.Increment) }) { Text("+") }
}Resolving from the registry
BlocBuilder(CounterBloc::class) { state ->
Text("Count: ${state.count}")
}Parameters
The StateEmitter to observe.
A composable receiving the latest state snapshot on every emission.
Overload that resolves the bloc from BlocRegistry by KClass.
BlocBuilder(CounterBloc::class) { state -> ... }A composable that rebuilds content only when buildWhen approves a state transition.
Unlike the plain BlocBuilder, this overload passes a state snapshot to content and updates that snapshot only when buildWhen(previous, current) returns true. This prevents UI sections from recomposing on every emission when only a specific field or threshold matters.
Usage
// Tier badge only redraws when the score crosses a tier boundary
BlocBuilder(
bloc = scoreBloc,
buildWhen = { old, new -> old / 10 != new / 10 },
) { state ->
TierBadge(tier = tierFor(state))
}The "previous" value passed to buildWhen is the last displayed state — what was last rendered — not the last emitted state. This mirrors the iOS BlocBuilderWhen behaviour.
Parameters
The StateEmitter to observe.
Predicate (previous, current) -> Boolean. Return true to approve a rebuild. The previous value is the last state that was approved and rendered.
A composable receiving the last approved state snapshot.
Overload that resolves the bloc from BlocRegistry by KClass.