I'm wondering if there's something I'm doing wrong...
# compose
n
I'm wondering if there's something I'm doing wrong, of if the API/Android Studio just doesn't support `Flow`s with the
@Preview
composables ATM
I have
Copy code
@ExperimentalAnimationApi
@Preview("list with different states")
@Composable
fun AListPreview() {
    AList(
        aa = flowOf(
            listOf(
                A(Id(1), "TODO #1"),
                A(Id(2), "TODO #2")
            )
        )
    )
}
and
Copy code
@ExperimentalAnimationApi
@Composable
fun AList(aa: Flow<List<A>>) {
    val state by aa.collectAsState(initial = emptyList())
    val deleted = remember { mutableStateListOf<A>() }

    LazyColumn(modifier = Modifier.fillMaxWidth()) {
        item {
            Text(
                text = stringResource(
                    id = R.string.main_aa,
                    state.size
                )
            )
        }
and the preview always displays the text with
0
and no rows obviously are displayed. Running actually the code in a emulator will display rows correctly
a
You will be able to see the list in interactive mode. I think preview mode only shows the initial state value (which is empty list in your case). For best practices, you should pass List<A> to AList function and collect flow as state in its parent composable and pass the collected flow's value (List<A>) to AList. It will increase reusability and you will be able to view preview with the list items.
👌 1
n
Right, state hoisting. Wonder how I didn't use that as it's the obvious answer...