flutter_staggered_grid_view icon indicating copy to clipboard operation
flutter_staggered_grid_view copied to clipboard

Setup corect scrollOffsets when on beggining of the list

Open centy opened this issue 1 year ago • 5 comments

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 avatar May 03 '23 14:05 centy

@letsar Are you still supporting this package?

centy avatar Jun 04 '23 18:06 centy

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.

letsar avatar Jun 05 '23 07:06 letsar

@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 avatar Jun 05 '23 07:06 centy

@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.

centy avatar Dec 16 '23 15:12 centy

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

glemartret avatar Aug 02 '24 09:08 glemartret