The Code A is from the official sample code
2- You can create a UI version of your model class and a extended property to your data class. You can
data class UiModel(
...
var expanded: Boolean = false
)
This way you can store extended state in your ViewModel.
LazyColumn(
content = {
items(tutorialList) { item: UiModel ->
var isExpanded by remember(key1 = item.title) { mutableStateOf(item.expanded) }
UiModel(
model = item,
onExpandClicked = {
item.expanded = !item.expanded
isExpanded = item.expanded
},
expanded = isExpanded
)
}
}
)
Result is