Feel like I've been out of the compose game for a ...
# compose
c
Feel like I've been out of the compose game for a few months and working on my first app in a while that has a list, but an
Item
in that list could also have a checkmark next to it to show that it's selected. What's the go-to? Option 1:
Copy code
var todos = mutableStateListOf<Pair<Item, Boolean>>()
Option 2:
Copy code
var todos = mutableStateListOf<Item>()

class Item(
  val id: Int,
// other stuff
  var selected by mutableStateOf(false),
)
Option 3:
Copy code
var todos = mutableStateListOf<Item>()
and make Item a data class so that I can copy it?
1️⃣ 1
2️⃣ 2
3️⃣ 7
s
just to offer an alternative not listed, you could maybe use another state holder to maintain the selected state separately from the Item class. this would allow
Item
to be immutable.
Copy code
class Item(val id: Int, val name: String)

var todos = mutableStateListOf<Item>()
var selectedTodos = mutableStateListOf<Int>()
not sure if you want to keep
selected
as a field on
Item
but you could persist the selected items separately as just the IDs of the items.
3
c
oh true. thanks for option 4 @Sterling Albury. Yeah in general I just hate the .copy() dance that you have to do. one of the nicest things about snapshot state is that it has a super nice api to make changes. i still have been meaning to try https://github.com/kopykat-kt/kopykat