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 |
This file contains 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
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 |
This file contains 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
//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. |