idootop / nested_scroll_view_plus

📜 An enhanced NestedScrollView with support for overscrolling for both the inner and outer scrollviews.
https://flutter-nested-scroll-view-plus.vercel.app
MIT License
27 stars 2 forks source link

If I use TabBarView in NestedScrollViewPlus, I cannot preserve the scroll positions. #6

Closed fikretsengul closed 4 months ago

fikretsengul commented 9 months ago

In fact, the problem is not exactly preserving the scroll positions, but rather not being able to preserve them separately. For example:

NestedScrollViewPlus(
  key: nestedScrollViewKey,
  controller: scrollController,
  headerSliverBuilder: (context, _) {
    ...
  },
  body: child,
);

ExtendedTabBarView(
  controller: _tabController,
  cacheExtent: 2,
  children: [
    CustomScrollView(
      key: PageStorageKey<UniqueKey>(UniqueKey()),
      physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
      slivers: [
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (context, index) {
              final number = index + 1;

              return Container(
                height: 50,
                color:
                    index.isEven ? CupertinoColors.lightBackgroundGray : CupertinoColors.extraLightBackgroundGray,
                alignment: Alignment.center,
                child: Text(
                  '$number',
                  style: CupertinoTheme.of(context).textTheme.textStyle,
                ),
              );
            },
            childCount: 20,
          ),
        ),
      ],
    ),
    CustomScrollView(
      key: PageStorageKey<UniqueKey>(UniqueKey()),
      physics: const BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()),
      slivers: [
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (context, index) {
              final number = index + 1;

              return Container(
                height: 50,
                color:
                    index.isEven ? CupertinoColors.lightBackgroundGray : CupertinoColors.extraLightBackgroundGray,
                alignment: Alignment.center,
                child: Text(
                  '$number',
                  style: CupertinoTheme.of(context).textTheme.textStyle,
                ),
              );
            },
            childCount: 20,
          ),
        ),
      ],
    )
  ],
);

In this configuration (I don't want to make my sliverappbar scrollable too), scrolling one view also scrolls other view.

https://github.com/idootop/nested_scroll_view_plus/assets/22684086/8aec98d5-27a4-4bea-8936-4a8a823b9416

Any suggestion to handle this case?

fikretsengul commented 9 months ago

extended_nested_scroll_view provides a fix for this (inner scrollables in tabview sync issue) Maybe we can extract the solution from this package or we can use extended_nested_scroll_view instead of original one to include other fixes too.

idootop commented 8 months ago

I was unable to replicate the issue you've mentioned. However, it appears that the key for your CustomScrollView is being regenerated as a new UniqueKey with each build: PageStorageKey<UniqueKey>(UniqueKey()). This could potentially be the root cause of the problem you're facing. I recommend consulting the official sample code here: https://github.com/idootop/nested_scroll_view_plus/blob/b9f9c553f24eab76666b66c3b25e45114190f74a/example/lib/main.dart#L64 It's essential to assign a consistent unique key to each scrollView under the tab view, instead of generating a new UniqueKey() for every build.

Junesui commented 2 months ago

same issue. and the sample code also has this problem https://github.com/idootop/nested_scroll_view_plus/blob/main/example/lib/main.dart