所以我想显示的帖子,我使用listview。在nestedscrollview主体中的Builder但当我向下滚动时,appbar不会被隐藏。这是listview的情况。只有当我把控制器分配给它时。如果我不这样做,那么它工作完美。
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
pinned: false,
floating: true,
snap: true,
forceElevated: innerBoxIsScrolled,
backgroundColor: Themes.secondaryColor,
automaticallyImplyLeading: false,
elevation: 0.0,
titleSpacing: 0,
toolbarHeight: 90,
title: Padding(
padding: const EdgeInsets.only(left:8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Trending",
style: GoogleFonts.roboto(
textStyle: const TextStyle(
fontSize: 20,
color: Color(0xff000000),
fontWeight: FontWeight.w500,
),
),
textAlign: TextAlign.left,
),
const SizedBox(height: 10,),
SizedBox(
width: double.infinity,
height: 27,
child: ListView.separated(
scrollDirection: Axis.horizontal,
physics: const BouncingScrollPhysics(),
itemCount: categories.length,
separatorBuilder: (context,index)=>const SizedBox(width: 5,),
itemBuilder: (context,index){
return Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: selectedIndex==index?Themes.primaryColor:Themes.primaryColor.withOpacity(0.5),
),
padding: const EdgeInsets.symmetric(vertical:5,horizontal: 12),
child: Text(
categories[index],
style: const TextStyle(color: Colors.white,fontSize: 13),
),
);
},
),
),
],
),
),
),
];
},
body: loading?const Center(child: CircularProgressIndicator(),
):ListView.separated(
controller: scrollController,
padding: const EdgeInsets.symmetric(vertical:15),
itemCount: posts.length,
separatorBuilder: (context,index)=>const SizedBox(height: 6,),
itemBuilder: (context,index)=>posts[index],
),
),
),
);
如果你只需要控制器做一些事情,如分页或监听滚动事件使用NotificationListener
,它将允许你这样做。