代码之家  ›  专栏  ›  技术社区  ›  Leong

滚动时Flutter容器重叠

  •  0
  • Leong  · 技术社区  · 1 年前

    我有一个如下所示的UI(img1),当我滚动UI时,渐变卡会稍微重叠它的父容器,但如果我删除了渐变,一切都很好。有没有办法在不去除我卡片中的渐变背景的情况下防止这种重叠?

    Img1:

    enter image description here

    Img2:

    enter image description here

    以下是我的示例代码:

    Container(
      margin: smallWidgetPadding,
      width: MediaQuery.of(context).size.width,
      decoration: ShapeDecoration(
          color: colorScheme.onPrimary,
          shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(30),
                  topRight: Radius.circular(30))),
          shadows: [BoxShadow(color: colorScheme.shadow, blurRadius: 5)]),
      child: Card(
          margin: margin,
          child: Container(
              decoration: ShapeDecoration(
                  gradient: gradient, shape: roundedRectangleBorderless),
              child: child)))
    
    1 回复  |  直到 1 年前
        1
  •  1
  •   Dhafin Rayhan    1 年前

    这个 clipBehavior 的属性 Container 默认为 Clip.none 。将其设置为 Clip.antiAlias 在外面 容器 .

    Container(
      clipBehavior: Clip.antiAlias,
      // ...
    )