Home > Mobile >  can't hide appbar in flutter with NestedScrollView
can't hide appbar in flutter with NestedScrollView

Time:03-18

Widget build(BuildContext context) {
return Scaffold(
  body: NestedScrollView(
    headerSliverBuilder: (context, innerBoxIsScrolled) =>
    SliverAppBar(
    title: Text('hide appbar'),
      centerTitle: true,
      leading: IconButton(
      icon: Icon(Icons.menu),
      onPressed: () {},
      ),
      actions: [
      IconButton(
      icon: Icon(Icons.search),
      onPressed: () {},
      )
      ],
//backgroundColor: Colors.purple,
      flexibleSpace: Container(
      decoration: BoxDecoration(
      gradient: LinearGradient(
      colors: [Colors.purple, Colors.red],
      begin: Alignment.bottomRight,
      end: Alignment.topLeft,
    ),
  ),
),
    ),

I fixed most of the issue but there is one last thing that keeps me run this code on my device. The error is The return type 'SliverAppBar' isn't a 'List<Widget>', as required by the closure's context. My body is wrapped with Singlechildscrollview. Is this why the NestedScrollView isn't working? Thanks for you help in advance

CodePudding user response:

You need to return List of widgets from headerSliverBuilder. SliverAppBar is a single widget and returning like this, showing the error. You can wrap it with List.

headerSliverBuilder: (context, innerBoxIsScrolled) 
         => [ SliverAppBar(...) ]
  • Related