Adding lists of Composables?

I have found that

val list: List<@Composable ()-> Unit> = listOf({Text("Cat")}, {Text("Dog")})

works, but

val list: List<@Composable ()-> Unit> = listOf({Text("Cat")}) + listOf({Text("Dog")})

produces the error “@Composable invocations can only happen from the context of a @Composable function” on the first Text().

Why is it that adding lists works fine with things like

val list: List<String> = listOf("Cat") + listOf("Dog")

but doesn’t seem to work with Composables? Is there a way how I can add lists of Composables to each other?

Leave a Comment