1

I have the same question as asked in this StackOverflow question, but for Jetpack Compose.

How can we get a list of items in Jetpack Compose when you're using Paging3 with LazyVerticalGrid, As using LazyVerticalGrid, we don't create any PagingDataAdapter.

1 Answer 1

-1

LazyPagingItems has the equivalent presenter APIs from PagingDataAdapter.

To get the whole list you can use LazyPagingItems.itemSnapshotList()

To access an item at a specific index without triggering page fetch, you can use LazyPagingItems.peek

Sign up to request clarification or add additional context in comments.

5 Comments

How do you use itemSnapshotList() if you want to collect it in a viewModel as collectAsLazyPagingItems() can only be invoked from a composable function?
@AkramHussain What do you want to accomplish by collecting the state in the viewModel?
I want to make an API request for a batch of items in the list.
I've been using ItemSnapshotList to access some fields with each item, but that kills automated pagination when using LazyPagingItems. I've had some success with peek and get, but if at the end of the list even peek will fail if I try to access an item beyond the end of the list to see another page will be loaded. How should I be checking for paginating when using the snapshot list?
@Martin what are you trying to achieve? Are you trying to manually trigger loading of the next page?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.