frank
11/29/2022, 11:33 AMFlow
properly in Compose Desktop, I have searched but only find examples for Android.
I get the data from Kmongo:
class TagDAO {
companion object {
private val tagsDB by lazy { Connection().getCollection<Tag>("tags") }
fun listTags(): Flow<Tag> {
return tagsDB.find().toFlow()
}
}
}
@Composable
fun form() {
val tagsFlow = TagDAO.listTags() // Flow<Tag>
val tagsState by tagsFlow.collectAsState(initial = Tag()) // Only return last value
}
hfhbd
11/29/2022, 11:37 AMby remember { tagDao.listTags() }.collectAsState()}
.
And what do you mean with last
value? A flow returns values over time. Compose updates your UI over time. So yeah, you always see the last value of the flow. If you want to show a list, you should fetch a list: Flow<List<Tag>>
frank
11/29/2022, 11:49 AMremember
to paste code.
Yes, I want obtain list of values. Kmongo
returns List<Tag>
or Flow<Tag>
, not like ROOM of Android that returns Flow<List<Tag>>
.