想要通过向下滚动而不显示到窗口顶部来显示SliverAppBar

时间:2020-07-29 13:26:28

标签: flutter dart

我正在制作新闻应用程序,并使用SliverAppBar隐藏和显示AppBar。

但是当向下滚动而不是窗口顶部时,我无法显示我的AppBar。 我该如何解决?

I can display AppBar on the top←gif

I cannot display when I'm not on the top←gif

    class NewsTab extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final newsListProvider = Provider.of<NewsListProvider>(context);
    final filterNames = newsListProvider.userFavoriteArtistNames;
    final List<Tab> filterTabs = filterNames.map((e) => Tab(text: e)).toList();
    print(newsListProvider.newsList);

    return DefaultTabController(
        length: filterTabs.length,
        child: Scaffold(
          body: new NestedScrollView(
//            controller: _scrollViewController,
            headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                new SliverAppBar(
                  backgroundColor: Color.fromRGBO(56, 238, 216, 1),
                  centerTitle: true,
                  title: Text("タイムライン",style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),),
                  leading: IconButton(
                    icon: Icon(Icons.search),
                    onPressed: () {},
                  ),
                 
                  pinned: true,
                  floating: true,
                  forceElevated: innerBoxIsScrolled,
                  bottom: TabBar(
                    tabs: filterTabs,
                    isScrollable: true,
                    labelColor: Color.fromRGBO(44, 233, 199, 1),
                    unselectedLabelColor: Colors.white70,
                    indicatorWeight: 0,
                    indicator:
                      CustomTabIndicator(),
                    ),
                ),
              ];
            },
            body: TabBarView(
                      children:
                      filterNames.map((e) => NewsList(filterName: e)).toList(),
                     )
          ),
        )
    );
  }
}

0 个答案:

没有答案