Make SliverAppBar scrollable when TabBarView child is scrolled

白昼怎懂夜的黑 提交于 2020-05-17 06:32:49

问题


I have home screen with bottom navigation consist of two items which all have ListView inside with infinite list and I want SliverAppBar to be scrollable when user scrolls in one of the list. Here is what I have so far

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 2,
        child: new Scaffold(
          body: CustomScrollView(
            slivers: <Widget>[
              SliverAppBar(
                snap: false,
                floating: false,
                pinned: true,
                expandedHeight: 160.0,
                flexibleSpace: FlexibleSpaceBar(
                  title: Text('Title'),
                ),
              ),
              SliverFillRemaining(
                child: TabBarView(
                  children: <Widget>[Items(), Activities()], //THESE HAVE LIST VIEW IN EACH 
                ),
              )
            ],
          ),
        ));
  }
}

And here is code of one of TabBarView children.

class Items extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<Widget> itemsWidgets = List.from(getItemsList()
        .map((Item item) => createItemWidget(context, item)));

    return Scaffold(
      body: Center(
        child: ListView(
          children: itemsWidgets,
        ),
      ),
    );
  }

  ListTile createItemWidget(BuildContext context, Item item) {
    return new ListTile(
      title: Text(item.sender.name),
      subtitle: Text('10:30 am'),
    );
  }
}

How can SilverAppBar be scrollable when user scrolls in one of the list? Any help/suggestion will be appreciated.


回答1:


Use NestedScrollView. There is an example in the api



来源:https://stackoverflow.com/questions/60967806/make-sliverappbar-scrollable-when-tabbarview-child-is-scrolled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!