Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

can't hide appbar in flutter with NestedScrollView

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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(...) ]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading