【发布时间】:2022-01-05 23:19:09
【问题描述】:
我正在尝试迭代 List 的对象,对于我想要显示可组合卡片的每个对象。问题是您不能从 list.forEach{} 括号内调用 Composable 函数。
代码:
@Composable
fun Greeting(listy : List<SomethingForLater>) {
LazyColumn {
listy.forEach {
//error here
testCard(somethingForLater = it)
}
}
}
@Composable
fun testCard(somethingForLater: SomethingForLater){
val theme = MaterialTheme
Card(shape = theme.shapes.small,backgroundColor = theme.colors.secondary){
Column {
Row {
Text(
text = somethingForLater.task,
modifier = Modifier.padding(start = 5.dp,
top = 3.dp,bottom = 3.dp
),
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
)
}
}
}
}
【问题讨论】:
标签: android android-jetpack-compose