简体   繁体   中英

SliverAppBar is not working even after adding expanded widget

What's the correct way to make a collapsible header in flutter?

I tried the following but it didn't work. What am I doing wrong and how can I fix it?

return CustomScrollView(
  shrinkWrap: true,
  slivers: [
    SliverAppBar(
      expandedHeight: 200,
      pinned: true,
      flexibleSpace: FlexibleSpaceBar(
        title: Text(title),
        background: Image(image: AssetImage(imgPath), fit: BoxFit.cover),
      ),
    ),
    SliverFillRemaining(
      child: Column(
        children: [Text('some cool text here')],
      ),
    )
  ],
);

Yes, it's a correct way and it works healthy. If you are asking why its not completely collapsing, you should check "pinned" value. If you set it "false" it will completely collapse.

  SliverAppBar(
   expandedHeight: 200,
   pinned: false,
   flexibleSpace: FlexibleSpaceBar(
    title: Text(title),
    background: Image(image: AssetImage(imgPath), fit: BoxFit.cover),
   ),
  ),

You can check this documentation for further information about SliverAppBar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM