【发布时间】:2021-08-21 07:23:54
【问题描述】:
我正在遍历一个循环以在可组合内呈现 UI。 在每次迭代下,我想对子列表(我想在异步 {} 中执行)执行某种排序和过滤,并使用该子列表来呈现 UI。
有没有办法等待 async{} 完成然后渲染 UI?
@Composable
fun MyTree(data: MutableList<Tree>) {
LazyColumn {
itemsIndexed(data) { index, tree ->
// Wanted to perform this operation inside async and use the result to be passed to composables below
val stems = tree.stems
?.sortedBy { it.age }
?.filter { it.living != 0 }
when (tree.type) {
TYPE1 -> Tree1(stems)
TYPE2 -> Tree1(stems)
TYPE3 -> Tree1(stems)
}
}
}
}
【问题讨论】:
标签: async-await kotlin-coroutines android-jetpack android-jetpack-compose