https://kotlinlang.org logo
a

Albert Francis

10/21/2021, 11:32 AM
Hey, I have
HorizontalPager
with
x many
items (can be 1 can be 20+) and each one of the item needs to call a BackEnd to fill it's information. So every time i receive a pageIndex i call
viewmodel.getMeSomeCake(index)
and when i receive it i want to fill the screen. I want to use StateFlow but i got the same problem as if it's a fragment with ViewPager. Pager creates the
n-1
,
n
,
n+1
pages so the data i got is not the one for the visible page. is there any recommended ways to do it on compose?
c

Colton Idle

10/21/2021, 4:04 PM
GW?
a

Albert Francis

10/21/2021, 6:29 PM
Backend-network
c

Colton Idle

10/21/2021, 9:32 PM
Seems like you should just not call getMeSomeCake if you already have the data? It's the same thing as images in a recyclerView. When that item is about to be shown, it tries to load the image, and then once it has the image, it just uses the image from your local cache.
a

Albert Francis

10/22/2021, 8:01 AM
the thing with the images, you call the network from recyclerview item or compose function and receive the response to the item not to the viewmodel. I don't have the data i only have a
key
that i know will give me the data for the visible page. I am hoping to use viewmodel and stateflow/sharedflow something to get the data and not call the BackEnd directly from compose and get the result to compose.
3 Views