I have API endpoint that returns a list of objects. I am using Paging 3 with pagingSource, flow in ViewModel, and collectAsLazyPagingItems. This list is passed to LazyColumn to show items on screen.
In LazyColumn items look like this
items(
count = list.itemCount,
key = list.itemKey { it.uuid },
contentType = list.itemContentType { it }
) { // composable here }
For example, I fetch 50 items on the first page (and the last item in the list has uuid: "xxx"). Scroll to the bottom and the new 50 items contain this item xxx, because the order was changed on the server while I was scrolling. And now I get the next error:
IllegalArgumentException: Key was already used
I don't want to remove unique keys from LazyColumn, because it improves performance. Are there any other ways to handle this case? What can I do to prevent this error while still using Paging 3?