letsar / flutter_staggered_grid_view

A Flutter staggered grid view
MIT License
3.14k stars 510 forks source link

Setup corect scrollOffsets when on beggining of the list #302

Open centy opened 1 year ago

centy commented 1 year ago

When using MasonryGridView with unique keys for each item like below:

child: MasonryGridView.count( 
                mainAxisSpacing: 10,
                crossAxisSpacing: 10,
                itemCount: state.imagesCount,
                itemBuilder: (context, index) => ImageTile(
                  key: Key(state.images[index].imagePath),
                  pictureInfo: state.images[index],
                  viewType: filter.type,
                ),
                crossAxisCount: 2,
              ),

and order of items changes then layout has holes mostly on second column. In my case any image can be moved to beginning of the list. So the newly moved image beaks logic that calculates offsets.

That fix prevents holes in image stream to appear

centy commented 1 year ago

@letsar Are you still supporting this package?

letsar commented 1 year ago

Hi @centy, yes I still maintain this package but I don't have a lot of time at the moment to do it properly. Can you explain me why this PR is fixing this issue? I don't really see the link between what you described and the fix.

centy commented 1 year ago

@letsar Issue appears if you have list of items, with keys. For some reason you want to reorder them, my case was to move any element to the beginning of the list. That action causes issue like this: before: 12 34 56

now move 3 on 1 position 3 <-empty space 12 45 6

Code when rebuilding offsets, calculates right offset starting not from 0. It is 100% reproducible

centy commented 10 months ago

@letsar Can you merge it or fix it? I am keeping changes on my branch. I would like to back to use stock version of the widget.

glemartret commented 2 months ago

I can confirm that this fixes the issue with empty spaces in Masonry grid. Could this be integrated in the public version ?