浮动appbar,appbar下方具有固定的tabbar

时间:2020-02-17 08:09:07

标签: flutter

我将NestedScrollView与SliverAppBar和Tabs结合使用。现在的问题是,我希望滚动tabview列表时折叠appbar,但是我希望折叠appbar时将其固定在顶部。下面是我正在使用的代码

 DefaultTabController(
  length: 4,
  initialIndex: 1,
  child:
  Scaffold(
    body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverOverlapAbsorber(
              handle:
                  NestedScrollView.sliverOverlapAbsorberHandleFor(context),
              child:
              SliverAppBar(
                title: Text('Title'),
                floating: true,
                pinned: false,
                forceElevated: innerBoxIsScrolled,
                bottom: TabBar(
                  indicatorColor: Colors.white,
                  isScrollable: true,
                  labelPadding: EdgeInsets.symmetric(vertical: 12),
                  indicatorSize: TabBarIndicatorSize.label,
                  tabs: <Widget>[
                    Tab(),
                    Tab()
                    Tab()
                    Tab()
                  ],
                ),
              ),
            ),
          ];
        },
        body: TabBarView(
          children: <Widget>[
            TabView1(),
            TabView2(),
            TabView3(),
            TabView14()
          ],
        )),
  ),
);

TabView2类的构建方法:

      return CustomScrollView(
        key: PageStorageKey<String>('chats'),
        slivers: <Widget>[
          SliverOverlapInjector(
            handle:
                NestedScrollView.sliverOverlapAbsorberHandleFor(context),
          ),
          SliverPadding(
            padding: const EdgeInsets.all(8.0),
            sliver: SliverList(
              delegate: SliverChildBuilderDelegate(
                  (BuildContext context, int index) {
                return
                  ListTile();
              }),
            ),
          )
        ],
      );

问题是,当我滚动列表int tabview2时,带有选项卡的应用栏会一起折叠。如果我在这里做错了,请告诉我。

0 个答案:

没有答案