awaitNullItemLoaded

fun <T> awaitNullItemLoaded(itemToWait: T?, extras: (T) -> Boolean = { true }, loadedContent: @Composable (T) -> Unit)

Method used to wait asynchronously the change of the state of a null item to its non-null value.

This method is useful in those scenarios where the content to display depends on the non-null item.

For example:

@Composable
override fun ArrangeScreenContent() {
    val text = remember { mutableStateOf<String?>(null) }

    // simulated waiting
    LaunchedEffect(Unit) {
        delay(1000)
        text.value = "Hello World!"
    }

    awaitNullItemLoaded(
        itemToWait = text.value,
        extras = null, // any extras condition
        loadedContent = { nullSafeText -> // non-null value
            // the UI content which depends on the text state
            Text(
                text = nullSafeText
            )
        }
    )
}

Parameters

itemToWait

The item initially null to wait

extras

Extra conditions to apply to show the loadedContent that depends on the non-null value of the itemToWait

loadedContent

The content to display when the itemToWait is not more null