Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private suspend fun loadPosts() {
viewModel.getAllPosts().collect { state ->
when (state) {
is State.Loading -> {
showToast("Loading")
}
is State.Success -> {
val postText = state.data.joinToString("\n") {
"${it.postContent} ~ ${it.postAuthor}"
}
binding.textPostContent.text = postText
}
is State.Failed -> showToast("Failed! ${state.message}")
} // END when
} // END collect
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment