简体   繁体   English

Flutter SliverList 在 SliverAppBar 上重叠

[英]Flutter SliverList Overlap on SliverAppBar

I'm trying to overlap a SliverList a few pixels over the SliverAppBar .我试图在SliverList上重叠几个像素的SliverAppBar I'd like the image in the FlexibleSpaceBar to go under the radius of my SliverList .我希望FlexibleSpaceBar中的图像在我的 SliverList 半径下为SliverList I can only get the radius.我只能得到半径。 Without the ability to overlap the SliverList onto the SliverAppBar .无法将SliverAppBar重叠到SliverList上。 在此处输入图像描述

return CustomScrollView(
      physics: BouncingScrollPhysics(),
      slivers: [
        SliverAppBar(
          backgroundColor: Colors.transparent,
          elevation: 0.0,
          expandedHeight: getProportionateScreenHeight(350),
          automaticallyImplyLeading: false,
          pinned: true,
          stretch: true,
          leading: Container(
            padding: EdgeInsets.fromLTRB(8.0, 8.0, 0.0, 0.0),
            child: SizedBox(
              height: getProportionateScreenWidth(40),
              width: getProportionateScreenWidth(40),
              child: FlatButton(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(60),
                ),
                color: Colors.white,
                padding: EdgeInsets.zero,
                child: Icon(Icons.arrow_back_ios),
                onPressed: () => Navigator.pop(context),
              ),
            ),
          ),
          actions: <Widget>[
            Container(
              padding: EdgeInsets.fromLTRB(0.0, 8.0, 8.0, 0.0),
              child: SizedBox(
                height: getProportionateScreenWidth(40),
                width: getProportionateScreenWidth(40),
                child: FlatButton(
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(60),
                  ),
                  color: Colors.white,
                  padding: EdgeInsets.zero,
                  child: Icon(Icons.more_vert),
                  onPressed: () {}
                ),
              ),
            ),
          ],
          flexibleSpace: FlexibleSpaceBar(
            //title: Text(_event.Title),
            centerTitle: true,
            stretchModes: [
              StretchMode.zoomBackground
            ],
            background: Stack(
              fit: StackFit.expand,
              children: <Widget>[
                Image.asset('assets/images/events/sunset.jpg', fit: BoxFit.cover),
                DecoratedBox(
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment(0.0, 0.5),
                      end: Alignment(0.0, 0.0),
                      colors: <Color>[
                        Color(0x60000000),
                        Color(0x00000000),
                      ],
                    ),
                  ),
                ),
              ]
            )
          )
        ),
        SliverList(
          delegate: SliverChildListDelegate([
            Column(
              children: [
                Container(
                  padding: EdgeInsets.only(top: getProportionateScreenHeight(20), bottom: getProportionateScreenHeight(100)),
                  child: EventDescription(event: _event),
                  decoration: BoxDecoration(
                    color: Color(0xFFF5F6F9),
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(40),
                      topRight: Radius.circular(40),
                    ),
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.withOpacity(0.5),
                        spreadRadius: 5,
                        blurRadius: 7,
                        offset: Offset(0, 0), // changes position of shadow
                      ),
                    ],
                  )
                ),
              ],
            )
          ]),
        )
      ]
    );

Would you like to use a workaround solution?您想使用变通解决方案吗? My solution is put the top part of the SliverList inside SliverAppBar .我的解决方案是将 SliverList 的顶部放在SliverAppBar中。

The only problem is that the fade out animation of flexiable space (while scrolling down) do effect to the top bar.唯一的问题是灵活空间的淡出 animation(向下滚动时)会对顶部栏产生影响。 (Because it is in the flexibleSpace ) (因为它在flexibleSpace

Due to SliverAppBar elevation is higher than SliverList .由于SliverAppBar海拔高于SliverList Any Scale or Translate to the widget always get the opposite result from your expected (SliverAppBar overlap on SliverList).对小部件的任何缩放或转换总是会得到与您预期相反的结果(SliverAppBar 在 SliverList 上重叠)。

I use stack to put the top part inside FlexibleSpaceBar, set collapseMode to CollapseMode.pin and set alignment to Alignment.bottomCenter :我使用stack将顶部放在 FlexibleSpaceBar 中,将 collapseMode 设置为CollapseMode.pin并将 alignment 设置为Alignment.bottomCenter

SliverAppBar(
  ...
  flexibleSpace: FlexibleSpaceBar(
    collapseMode: CollapseMode.pin,
    ...
    background: Stack(
      ...
      children: [
        ...
        Align(
          alignment: Alignment.bottomCenter,
          child: Container(
            child: Container(
              height: _height, // 40
            ),
            decoration: BoxDecoration(
              color: Color(0xFFF5F6F9),
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(40),
                topRight: Radius.circular(40),
              ),
              boxShadow: [
                BoxShadow(
                  color: Colors.grey.withOpacity(0.5),
                  spreadRadius: 5,
                  blurRadius: 7,
                  offset: Offset(0, 0), // changes position of shadow
                ),
              ],
            ),
          ),
        ),
      ]
     ...

If you need to use collapseMode: CollapseMode.parallax like the default setting do, the _height need to be dynamical during scrolling.如果您需要像默认设置一样使用collapseMode: CollapseMode.parallax ,则_height在滚动期间需要是动态的。

void initState(){
  _scrollController = ScrollController()..addListener(() {
    setState(() {
      _height = math.max(_scrollController.offset*_topBarFactor +_topBarHeight,_topBarHeight);
    });
}
});

在此处输入图像描述

暂无
暂无

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

相关问题 Flutter:如何允许内容与 SliverAppBar 重叠? - Flutter : how Allow content to overlap SliverAppBar? Flutter:如何将 RefreshIndicator 与 SliverAppBar 一起使用 - Flutter: How to use RefreshIndicator with SliverAppBar 如何为 flutter 中的 sliverList 提供固定高度? - How to give fixed height to a sliverList in flutter? 鼠标滚动在 SliverAppbar() 或 SliverAppbar() 上浮动不起作用 Flutter Web - Mouse scroll not work on SliverAppbar() or SliverAppbar() floating not working Flutter Web 在 sliverappbar 滚动时颤动将状态栏更改为黑色 - flutter change status bar to dark on sliverappbar scrolling flutter 中 SliverAppBar 中资产的背景图像错误 - Error in background image from asset in SliverAppBar in flutter 是否可以在flutter中为SliverList内的按钮实现一个可禁用的窗口小部件 - is it Possible to Implement a Dismissible widget for a button inside a SliverList in flutter 向下滚动时隐藏的 Flutter TabBar 和 SliverAppBar - Flutter TabBar and SliverAppBar that hides when you scroll down Flutter SliverAppBar 和 FlexibleSpaceBar 在向上滚动时呈现与 FlexibleSpaceBar 的标题参数不同的小部件 - Flutter SliverAppBar and FlexibleSpaceBar which Renders a different widget other than title param of FlexibleSpaceBar on scrolling up 我如何为 SliverAppBar 设置动画以固定并在 customscrollview 顶部滚动? flutter - How can i animate SliverAppBar to be pinned and also scroll on top of the customscrollview? flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM