flutter_staggered_grid_view icon indicating copy to clipboard operation
flutter_staggered_grid_view copied to clipboard

using multiple SliverMasonryGrid in a CustomScrollView

Open sgbai78 opened this issue 1 year ago • 5 comments

When using multiple SliverMasonryGrid in a CustomScrollView to draw a grid with different crossAxisCount, the scroll position is reset when scrolling the first SliverMasonryGrid.

This was not an issue when using multiple SliverLists or SliverGrid.

I used the code like this.

@override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        SliverAppBar(
          flexibleSpace: FlexibleSpaceBar(
            background: Image.network(
              'https://cdn.pixabay.com/photo/2016/09/30/14/56/venetian-1705528_960_720.jpg',
              fit: BoxFit.cover,
            ),
            collapseMode: CollapseMode.none,
          ),
          expandedHeight: 150,
        ),
        SliverPadding(
          padding: const EdgeInsets.only(top: 8, left: 8, right: 8, bottom: 8),
          sliver: SliverMasonryGrid.count(
            crossAxisCount: 2,
            mainAxisSpacing: 8,
            crossAxisSpacing: 8,
            childCount: _items.length,
            itemBuilder: (_, index) {
              return Container(
                height: 200,
                color: Colors.grey,
                child: Center(
                  child: Text('Grid Item $index'),
                ),
              );
            },
          ),
        ),
        SliverPadding(
          padding: const EdgeInsets.only(top: 8, left: 8, right: 8, bottom: 8),
          sliver: SliverMasonryGrid.count(
            crossAxisCount: 1,
            mainAxisSpacing: 8,
            crossAxisSpacing: 8,
            childCount: _items.length,
            itemBuilder: (_, index) {
              return Container(
                height: 200,
                color: Colors.grey,
                child: Center(
                  child: Text('Grid Item $index'),
                ),
              );
            },
          ),
        ),
        SliverPadding(
          padding: const EdgeInsets.only(top: 8, left: 8, right: 8, bottom: 8),
          sliver: SliverMasonryGrid.count(
            crossAxisCount: 1,
            mainAxisSpacing: 8,
            crossAxisSpacing: 8,
            childCount: _items.length,
            itemBuilder: (_, index) {
              return Container(
                height: 200,
                color: Colors.grey,
                child: Center(
                  child: Text('Grid Item $index'),
                ),
              );
            },
          ),
        ),
      ],
    );
  }

sgbai78 avatar Apr 21 '23 09:04 sgbai78

same problem

Mr-yuwei avatar May 19 '23 06:05 Mr-yuwei

I am also having same problem and same issue is already reported in this repository. See here #286

DaniyalDolare avatar May 20 '23 11:05 DaniyalDolare

I have a similar problem using SliverMasonryGrid and SliverList in CustomScrollView. The SliverList is placed below the SliverMasonryGrid, and the scroll position jumps to the SliverMasonryGrid when I scroll down to SliverList. I tried to replace SliverList with a widget wrapped in SliverBoxToAdapter, but the problem still occurs.

aaron-chu avatar Jun 15 '23 01:06 aaron-chu

same problem, any solution for this.

phucdth12a avatar Sep 22 '23 07:09 phucdth12a

Looks like there is a related issue with flutter's SliverGrid https://github.com/flutter/flutter/issues/136573

CrypticVader avatar Oct 16 '23 12:10 CrypticVader