Ayfri
08/06/2022, 12:23 AMDerek Ellis
08/06/2022, 12:42 AM.await()
extension on the promise to turn it into a coroutine, and then you can treat it like you would treat any data coming from an ordinary coroutine.Ayfri
08/06/2022, 12:43 AMDerek Ellis
08/06/2022, 12:45 AM@Composable
fun MyComposable() {
var theList by mutableStateOf(emptyList())
LaunchedEffect(Unit) {
theList = getData().await()
}
theList.forEach {
// ...
}
}
Ayfri
08/06/2022, 12:47 AMDerek Ellis
08/06/2022, 12:48 AMclass MyViewModel {
val theListData: Flow<List<?>> = flow {
emit(getData().await())
}
}
@Composable
fun MyComposable(viewModel: MyViewModel) {
val theList by viewModel.theListData.collectAsState(emptyList())
theList.forEach {
// ...
}
}
Ayfri
08/06/2022, 12:50 AMKtor
and kotlinx.serialization
, so I get the entire list at once so I don't need any flow, also the list is just less than 100 items, they have quite a lot of data but it's almost only literal values and other are not that bigandylamax
08/07/2022, 10:50 PM