简体   繁体   English

即使在添加扩展小部件后,SliverAppBar 也无法正常工作

[英]SliverAppBar is not working even after adding expanded widget

What's the correct way to make a collapsible header in flutter?在 flutter 中制作可折叠 header 的正确方法是什么?

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.如果将其设置为“false”,它将完全崩溃。

  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.您可以查看文档以获取有关 SliverAppBar 的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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