How can I add a Button on bottom of SliverAppBar and make it overlap on ExtentList?

試著忘記壹切 提交于 2020-01-25 06:52:30

问题


I've try to put a Column(a Container inside) in SliverAppBar bottom property as a button, but it can't overlap the ExtentList ,just overflow the bottom margin. I want to make it overlapped just like Spotify App do.

this is Spotify Sample: https://imgur.com/VrZRY4c

this is what I've tried: https://imgur.com/4bNZw8j

My code:

class _MenuListState extends State<MenuList> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverPadding(
            padding: EdgeInsets.only(top: 10, bottom: 10),
            sliver: SliverAppBar(
              pinned: true,
              expandedHeight: 300,
              title: Text(
                'Testing',
                style: TextStyle(color: Colors.red),
              ),
              flexibleSpace: FlexibleSpaceBar(
                title: Text(''),
                background: Image.asset(
                  'images/w.jpg',
                  fit: BoxFit.cover,
                ),
              ),
              bottom: PreferredSize(
                child: Column(children: <Widget>[
                  Text(
                    'test',
                    style: TextStyle(),
                  ),
                  Container(
                    decoration: BoxDecoration(
                      color: Color.fromRGBO(109, 76, 65, 1),
                      borderRadius: BorderRadius.all(
                        Radius.circular(20),
                      ),
                    ),
                    height: 54,
                    width: 100,
                  ),
                ]),
              ),
            ),
          ),
          SliverFixedExtentList(//extentlist)
        ],
      ),
    );
  }
}

回答1:


Try this

class _MenuListState extends State<MenuList> {
  static const double _appBarBottomBtnPosition =
      24.0; //change this value to position your button vertically

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text(
              'Testing',
              style: TextStyle(color: Colors.red),
            ),
          ),
          SliverAppBar(
            pinned: true,
            expandedHeight: 300.0,
            flexibleSpace: FlexibleSpaceBar(
              centerTitle: true,
              titlePadding: EdgeInsets.only(bottom: 25),
              title: Text('Title'),
              background: Image.asset(
                'images/w.jpg',
                fit: BoxFit.cover,
              ),
            ),
            bottom: PreferredSize(
              preferredSize: const Size.fromHeight(0.0),
              child: Transform.translate(
                offset: const Offset(0, _appBarBottomBtnPosition),
                child: RaisedButton(
                  shape: StadiumBorder(),
                  child: Text("Click Here"),
                  onPressed: () {},
                ),
              ),
            ),
          ),
          SliverPadding(
            padding: EdgeInsets.only(top: _appBarBottomBtnPosition),
          ),
          SliverFixedExtentList(
              //extentlist
          ),
        ],
      ),
    );
  }
}


来源:https://stackoverflow.com/questions/59403258/how-can-i-add-a-button-on-bottom-of-sliverappbar-and-make-it-overlap-on-extentli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!