简体   繁体   English

在其他小部件上飘动阴影

[英]Flutter shadow over other widgets

My base widget is a Column.我的基本小部件是一个列。 The first element is a Container which has a BoxShadow.第一个元素是具有 BoxShadow 的 Container。 The second element is a ListView which builds several Card, depending on the context.第二个元素是一个 ListView,它根据上下文构建多个 Card。 If the scroll is 0 the shadow gets displayed.如果滚动为 0,则显示阴影。 However when start scrolling, the card is "over" the shadow (higher z-index) and hides it.然而,当开始滚动时,卡片“超过”阴影(较高的 z-index)并将其隐藏。

不滚动时阴影可见 在此处输入图片说明

The shadow should stay always on top, over the Cards.阴影应始终位于卡片上方。 How is this done?这是怎么做的?

Code would be really helpful to solve that.代码对于解决这个问题真的很有帮助。 But I have an idea what problem you are facing and how it can be solved.但是我知道您面临什么问题以及如何解决。

Try to use Stack instead of Column , because Column take the whole space of the screen.尝试使用Stack而不是Column ,因为Column占据了整个屏幕空间。 Thus it's overlapping the shadow.因此它重叠了阴影。 Stack will help you to show the Container above your ListView . Stack将帮助您在ListView上方显示Container Also use Positioned .也使用Positioned Your ListView needs an offset from the top ListItem otherwise it will be covered by the Container and can't be touched anymore.您的ListView需要与顶部ListItem的偏移量,否则它将被Container覆盖并且无法再被触摸。

Stack(
  children: <Widget>[
    Padding(
      //padding
      child: //Listview (can also be wrapped in "Positioned")
    ),
    Positioned(
      top: 0.0, //Container at the top, ListView needs an additional offset from top, otherwise it will be covered by Container
      left: 0.0,
      right: 0.0,
      child: Container(
        decoration: BoxDecoration(
          color: //put some color
          boxShadow: [
            BoxShadow(
              color: //put some color
              offset: Offset(0, 10), //offset
              // also can do some blur etc.
          )]
        ),
        child: ListTile(
          title: //choose your title
        )
     ),
    ),
  ]
)

将这个上部框包裹在Material小部件中并提供一个高度。

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

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