Hello, Can someone please explain the problem of u...
# compose
s
Hello, Can someone please explain the problem of using key in lazy column? I’m facing the same problem.
Copy code
<https://stackoverflow.com/questions/74381205/removing-item-from-the-list-causes-wrong-display-in-lazycolumn>
a
as the reply to the question explains, you need the items inside the
items
callback to be associated with a key. that way, when an item is removed, the LazyColumn knows what is removed. In that example, say each
Person
had a field called id, which was unique to it. Then you'd write
Copy code
items(people.size, key = { index -> people[index].id }) { etc ...
s
Someone told me there is a problem or crash while using key in lazy column, is it so?
a
this
key
function associates an index with an id, so when an item is removed and all the indices of the items change, the key callback now reconnects the index to the item it should contain properly
dont see why, have you tried it?
s
not yet
a
give it a go, if it crashes you then actually have an exception to google
s
good one 👍
Thanks abbic