代码之家  ›  专栏  ›  技术社区  ›  woshitom

如何在SilverAppBar中仅显示选项卡视图

  •  0
  • woshitom  · 技术社区  · 6 年前

    我基本上希望在我的页面中间有一个TabVIEW导航。 我的SliverAppBar仅由我的TabView组成,我将我的TabView包装在SliverAppBar中,以便使用pinted:true property。

    return Scaffold(
          appBar: AppBar(
            title: Text('Title'),
          ),
          body: NestedScrollView(
    
            headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
              return <Widget>[
                SliverToBoxAdapter(
                    child: Container(
                  height: 500,
                  color: Colors.red,
                )),
    
              SliverAppBar(
                  pinned: true,
                  bottom: TabBar(
                    tabs: <Widget>[
                      Tab(
                        text: "Home",
                        icon: Icon(Icons.home),
                      ),
                      Tab(
                        text: "Example page",
                        icon: Icon(Icons.help),
                      )
                    ],
                    controller: _tabController,
                  )),
    
              ];
            },
            body: TabBarView(
              children: <Widget>[
                PageExample(),
                PageExample(),
              ],
              controller: _tabController,
            ),
          ),
        );
    

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  0
  •   woshitom    6 年前

    我需要将expandedHeight设置为0:

    返回脚手架( appBar:appBar( 标题:文本(“标题”), ), 正文:嵌套滚动视图(

        headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
          return <Widget>[
            SliverToBoxAdapter(
                child: Container(
              height: 500,
              color: Colors.red,
            )),
    
          SliverAppBar(
              expandedHeight: 0,
              pinned: true,
              bottom: TabBar(
                tabs: <Widget>[
                  Tab(
                    text: "Home",
                    icon: Icon(Icons.home),
                  ),
                  Tab(
                    text: "Example page",
                    icon: Icon(Icons.help),
                  )
                ],
                controller: _tabController,
              )),
    
          ];
        },
        body: TabBarView(
          children: <Widget>[
            PageExample(),
            PageExample(),
          ],
          controller: _tabController,
        ),
      ),
    );