BlocKotlin

BlocKotlin

A Kotlin implementation of the Bloc pattern for building Android applications in a consistent, testable, and understandable way, using Jetpack Compose.

Inspired by the Dart Bloc library — a Kotlin port of the bloc package originally created by Felix Angelov for Flutter/Dart. The same event-driven state-management pattern, brought natively to Android with Kotlin and Jetpack Compose. See the BlocSwift project for the iOS/Swift counterpart.

Getting started

dependencies {
implementation("io.github.sergiofraile:bloc:1.1.2")
}
import dev.bloc.Bloc

class CounterBloc : Bloc<Int, CounterEvent>(initialState = 0) {
init {
on<Increment> { _, emit -> emit(state + 1) }
on<Decrement> { _, emit -> emit(state - 1) }
}
}

Full guide, core concepts, Compose integration, and examples are in the README on GitHub.

Key types

TypePurpose
CubitMinimal state container — emit new state directly via functions
BlocEvent-driven state container — map incoming events to state transitions
HydratedBlocBloc that persists and restores its state across process death
BlocProvider / blocState()Compose integration for scoping and observing blocs
BlocObserverGlobal hook into every bloc's lifecycle, events, and errors
EventTransformerControl event concurrency (sequential, droppable, restartable, …)

Packages

Link copied to clipboard
Link copied to clipboard