Skip to content

Instantly share code, notes, and snippets.

View AndroidPoet's full-sized avatar
God Mode

Ranbir Singh AndroidPoet

God Mode
View GitHub Profile

Kotlin Flow Cheat Sheet

Flow Types

Flow Type Purpose Key Features Use Case
flow {} Creates a cold flow that emits values lazily. Emits values only when collected.
Supports suspending functions.
Creating custom flows to emit data on demand.
flowOf() Creates a flow from a fixed set of values. Emits provided values sequentially.
Cold by nature.
Emit predefined values (e.g., configuration settings).
asFlow() Converts collections, sequences, arrays, or ranges to flows. Supports many standard types.
Cold by nature.
Convert lists or arrays into flows for processing.
`c
import androidx.compose.animation.core.*
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
//Add these lines inside your MainActivity.
if (Build.VERSION.SDK_INT >= 30) {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
// Apply the insets as a margin to the view. Here the system is setting
// only the bottom, left, and right dimensions, but apply whichever insets are
// appropriate to your layout. You can also update the view padding
// if that's more appropriate.