a

    Albert Francis

    11 months ago
    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?
    Colton Idle

    Colton Idle

    11 months ago
    GW?
    a

    Albert Francis

    11 months ago
    Backend-network
    Colton Idle

    Colton Idle

    11 months ago
    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

    11 months ago
    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.