当我向上滚动时,SliverAppBar 中的 FlexibleSpace 没有隐藏它的内容

FlexibleSpace in SliverAppBar is not hiding it's contents when I scroll up

问题:

为什么我向上滚动时flexibleSpace里面的内容没有隐藏?

这是我的代码:

class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
  return Scaffold(
    body: CustomScrollView(
      physics: PageScrollPhysics(),
      slivers: [
        SliverAppBar(
          title: Text('Dashboard'),
          actions: [
            CircleAvatar(
              backgroundColor: Colors.transparent,
              backgroundImage: NetworkImage('https://i.pinimg.com/originals/da/51/c2/da51c26fe3398b0f8314fee17a98e0e7.jpg'),
            ),
            SizedBox(width: 10.0),
          ],
          floating: false,
          pinned: true,
          expandedHeight: 300.0,
          flexibleSpace: Stack(
            children: <Widget>[
              Positioned.fill(
                child: Image.network(
                  "https://images.wallpapersden.com/image/download/colorful-neon-bubbles_a2dtaWmUmZqaraWkpJRmbmdlrWZlbWU.jpg",
                  fit: BoxFit.cover,
                )
              ),
              Center(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text('Join as our member now,\nget discount upto 70%', style: TextStyle(color: Colors.white),),
                    SizedBox(height: 8.0),
                    RaisedButton(
                      child: Text('Subscribe now', style: TextStyle(color: Colors.red),),
                      onPressed: () {},
                    )
                  ],
                ),
              )
            ],
          ),
        ),
        SliverList(
        delegate: SliverChildListDelegate([
          Container(
            height: 500.0,
              ),
            ]),
          )
        ],
      ),
    );
  }
}

编辑:我试过了,但没用。

bottom: PreferredSize(
  preferredSize: Size.fromHeight(0),
  child: ... 

添加一个 FlexibleSpaceBar,然后你的 Stack 作为它的 background,像这样:

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        physics: PageScrollPhysics(),
        slivers: [
          SliverAppBar(
              title: Text('Dashboard'),
              actions: [
                CircleAvatar(
                  backgroundColor: Colors.transparent,
                  backgroundImage: NetworkImage(
                      'https://i.pinimg.com/originals/da/51/c2/da51c26fe3398b0f8314fee17a98e0e7.jpg'),
                ),
                SizedBox(width: 10.0),
              ],
              floating: false,
              pinned: true,
              expandedHeight: 300.0,
              flexibleSpace: FlexibleSpaceBar(
                background: Stack(
                  children: <Widget>[
                    Positioned.fill(
                        child: Image.network(
                      "https://images.wallpapersden.com/image/download/colorful-neon-bubbles_a2dtaWmUmZqaraWkpJRmbmdlrWZlbWU.jpg",
                      fit: BoxFit.cover,
                    )),
                    Center(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Text(
                            'Join as our member now,\nget discount upto 70%',
                            style: TextStyle(color: Colors.white),
                          ),
                          SizedBox(height: 8.0),
                          RaisedButton(
                            child: Text(
                              'Subscribe now',
                              style: TextStyle(color: Colors.red),
                            ),
                            onPressed: () {},
                          )
                        ],
                      ),
                    )
                  ],
                ),
              )),
          SliverList(
            delegate: SliverChildListDelegate([
              Container(
                height: 500.0,
              ),
            ]),
          )
        ],
      ),
    );
  }
}