Landry Norris
07/26/2021, 9:45 PMcollect { value = it }
inside of collectAsState() does get called, and 'it' has the correct value, but the UI does not change. The UI did properly respond when I used LiveData and observeAsState(), but I am wanting to switch to Flows.Zach Klippenstein (he/him) [MOD]
07/26/2021, 9:50 PMcollectAsState
?Landry Norris
07/26/2021, 9:51 PMval itemsState = viewModel.filteredItems.collectAsState(initial = ArrayList())
LazyColumn(modifier = Modifier.fillMaxSize()) {
itemsIndexed(itemsState.value) { _, item ->
Card {
TodoRow(
item = item,
onStarClicked = viewModel::onStarClicked,
onTextChanged = viewModel::setNote,
onDoneClicked = viewModel::onDoneClicked,
onTrashClicked = viewModel::onTrashClicked
)
}
}
}
Zach Klippenstein (he/him) [MOD]
07/26/2021, 9:52 PMfilteredItems
property defined?ArrayList
on every recomposition, just to immediately throw it awayLandry Norris
07/26/2021, 9:52 PMval filteredItems = MutableSharedFlow<MutableList<ToDoItem>>(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
Zach Klippenstein (he/him) [MOD]
07/26/2021, 9:53 PMArrayList
directly but instead use List
as the type and listOf()
to create themMutableSharedFlow
hold a MutableList
? Are you mutating it ever?Landry Norris
07/26/2021, 9:58 PMZach Klippenstein (he/him) [MOD]
07/26/2021, 11:08 PMlistOf
uses an ArrayList under the hood i believe, so it should still workLandry Norris
07/26/2021, 11:45 PMyousefa2
07/27/2021, 5:47 AMLazyColumn
.
LazyColumn
takes a lambda that allows you to compute a key per item. If you don't supply this lambda it uses the item index as key.Landry Norris
07/27/2021, 2:17 PM