Photo_view: get current page index inside loadingbuilder

Created on 13 Aug 2020  路  8Comments  路  Source: fireslime/photo_view

Is your feature request related to a problem? Please describe.
I am unable to get the current page index inside the loadingbuilder.
When I try to set the index inside the builder,
the images will switch around, because the index is set twice, by both pages

Describe the solution you'd like
Get the current page index passed into the loadingbuilder

Describe alternatives you've considered
Trying to set the index inside the builder with a variable that spans the entire context.

Additional context
8153171

the code I tried for this looks something like this:

int current;
return PhotoViewGallery.builder(
    builder: (BuildContext context, int index) {
        current = index;
        imageProvider: CachedNetworkImageProvider(sourceImages[index]),
    },
    loadingBuilder: (buildContext, imageChunkEvent) => CachedNetworkImage(
        imageUrl: previewImages[current],
    ),
),

the issue I was having with my workaround is basically, that the next image in the pageview gets loaded while the first one also gets loaded, because the current int is set by the both page that are loaded by the pageview.

Priority bug

Most helpful comment

I think it would still be nice to have the loading builder inside the options.

All 8 comments

Setting a control variable (current) via builder creates a race condition. This happens because the index passed to Pageview's builder is the source of truthness only inside the builder scope. Outside of it, we can't rely on that since we have a state when we have two pages in display (like in the middle of a swipe gesture) and both builders (for each page) got to run.

To get to know the "current" page, use PageController.page (PhotoViewGallery supports that).

beautiful, that should to it. thank you.

oh no, that doesnt work either, @renancaraujo .
because PageController.page is a double,
and rounding it will not work either because the next page will be loaded while the double is closer to the current one etc.

You have to use animateToPage

馃 I am a bit confused now.
How would animateToPage help me get the current index inside the loadingbuilder?
I am not setting the page manually anywhere.

For sure, loadingBuilder has to be moved to PhotoViewGalleryPageOptions

I have solved this with #339

I think it would still be nice to have the loading builder inside the options.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nobutakaes picture nobutakaes  路  4Comments

darrylong picture darrylong  路  5Comments

hugocbpassos picture hugocbpassos  路  4Comments

barangungor picture barangungor  路  7Comments

renancaraujo picture renancaraujo  路  4Comments