【发布时间】:2021-12-15 05:12:41
【问题描述】:
我在 compose 中尝试了范围函数,但有些东西让我感到困惑。 我在位置 1 遇到错误:'@Composable 调用只能在 @Composable 函数的上下文中发生',但我不知道为什么。
@Composable
fun scope_test() {
val isOk: Boolean? = false
Column() {
isOk?.let {
Text(text = "That's it!")
} ?: {
Text(text = "Nothing!") // place 1: error
}
isOk?.let {
Text(text = "That's it!")
} ?: run { Text(text = "Nothing!") }
isOk?.let {
Text(text = "That's it!")
} ?: Text(text = "Nothing!")
}
}
【问题讨论】:
标签: android kotlin android-jetpack-compose