Keep your list outside a composable so you have access to it everywhere. Preferably inside a ViewModel.
val items = mutableStateListOf<TodoItem>()
mutableStateListOf
does have addAll()
, so no need to use apply()
.
Update the item the same way, but always check if the index is valid.
val index = items.indexOfFirst { it.id == item.id }
if (index != -1) {
items[index] = items[index].copy(urgent = it)
}
Also remember to add a key to your LazyColumn so it actually updates properly.
items(items, key = { it.id }) {
//content here
}