0

I have this code to make a page which has a TabBar with content above it and a TabBarView below the TabBar. Scrolling the TabBarView causes the TabBar to move up the page from it's initial position until it reaches the top.

However, I want the user to be able to drag the TabBar at any time to move it up and down. Currently, if you try to drag the TabBar, the TabBarView scrolls instead.

Demo:

Here you can see scrolling up the TabBarView normally, and then attempting to drag the TabBar down but the TabBarView scrolling instead: https://imgur.com/a/vUusqyq

Code:

                    NestedScrollView(
                      headerSliverBuilder:
                          (BuildContext context, bool innerBoxIsScrolled) {
                        return <Widget>[
                          SliverToBoxAdapter(
                            child: pageHeaderContent,
                          ),
                          SliverPersistentHeader(
                            pinned: true,
                            delegate: _SliverTabBarDelegate(tabBar),
                          ),
                        ];
                      },
                      body: TabBarView(
                        controller: _tabController,
                        children: [
                          for (var tabItem in tabItems)
                              tabItem.page,
                        ],
                      ),
                    ),

1 Answer 1

0

using SliverAppBar may achieve what you want

example

          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
              SliverOverlapAbsorber(
                handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                sliver: SliverAppBar(
                  surfaceTintColor: Colors.white,
                  flexibleSpace: pageHeaderContent,
                  pinned: true,
                  expandedHeight: 150.0,
                  forceElevated: innerBoxIsScrolled,
                  bottom: tabBar,
                ),
              ),
            ];
          },

NestedScrollView document

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.