Home > front end >  App bar doesn't hide on scroll in nestedscrollview flutter
App bar doesn't hide on scroll in nestedscrollview flutter

Time:10-05

So i want to show posts and for that am using listview.builder in the body of nestedscrollview but when i scroll down then appbar doesn't get hided. This is in case of listview.builder only if i assign controller to it. If i don't then it works perfectly.

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],
          ),
        ),
      ),
    );

CodePudding user response:

If you only need the controller to do something like pagination or listen to scroll event use NotificationListener it will allow you to do that.

  • Related