Jetpack Compose is Android’s declarative UI: @Composable functions emit UI, Modifier handles padding/clicks/size, and state (remember + mutableStateOf or ViewModel StateFlow) triggers recomposition. Use LazyColumn for lists. Keep composables skippable by passing stable parameters and avoiding work in the function body.
This Kotlin cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.
Quick reference
- Composable:
@Composable fun Title(text: String)— must be called from another composable (or setContent). - Modifier: Chain:
Modifier.fillMaxWidth().padding(16.dp).clickable { }. - State:
var n by remember { mutableStateOf(0) }for local UI. Hoist state to ViewModel for real data. - Recompose: When a read state changes, the composable runs again. Keep them cheap.
- LazyColumn: Virtualized list.
items(list, key = { it.id }) { ... }. - Side effects:
LaunchedEffect(key)for coroutines.DisposableEffectfor listeners. - Theming:
MaterialThemecolors/typography. Do not hardcode colors in every widget. - Preview:
@Previewin Android Studio. Previews cannot hit the network.
Copy-paste examples
Stateful column and a lazy list
Keys on items preserve state when the list reorders. Read state in the composable that needs it.
@Composable
fun Counter() {
var n by remember { mutableStateOf(0) }
Column(Modifier.padding(16.dp)) {
Text("Taps: $n")
Button(onClick = { n++ }) { Text("Add") }
}
}
@Composable
fun Titles(rows: List<Project>) {
LazyColumn {
items(rows, key = { it.id }) { row ->
Text(row.title, Modifier.padding(16.dp))
}
}
}Common mistakes
- Doing network in a composable body instead of a ViewModel / LaunchedEffect.
- Using
RecyclerViewmental models and fighting recomposition with randomrememberon everything. - Missing
keyin LazyColumn so scroll state jumps. - Passing
Modifieronly to the outer box and wondering why clicks miss padding.
FAQ
- Compose vs XML views? New Google samples are Compose-first. XML still exists in older apps. You can mix via
AndroidView/ComposeView.
- Does Compose use Kotlin only? The UI is Kotlin. You can still have Java modules, but composables are Kotlin functions.
- Why did my UI not update? You mutated a list in place without replacing the
Statevalue. UsetoMutableList()and assign a new list, or a snapshot list.
Related Kotlin cheat sheets
Build with this stack
When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds mobile app development and also sells ready-made source code. Request a quote and tell us the stack.
Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.