我可以溢出容器中的小部件以使其像被剪裁一样吗?

Ken*_*ith 5 flutter

我按照下图进行操作,但当我尝试制作白色气泡时遇到了一些困难。

在此输入图像描述

我尝试过使用OverFlowBox另一篇文章Flutter mask 将一个圆圈放入容器中的方法,但我将圆圈卡在了中间Container,我不知道为什么alignment无法帮助移动它。这是我尝试过的:

return Container(
  alignment: Alignment.topCenter,
  height: screenHeight/3.5,
  width: screenWidth/3.5,
  decoration: BoxDecoration(
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(10),
      topRight: Radius.circular(60),
      bottomLeft: Radius.circular(10),
      bottomRight: Radius.circular(10),
    ),
    gradient: LinearGradient(
      begin: FractionalOffset.topLeft,
      end: FractionalOffset.bottomRight,
      colors: [boxColorBegin, boxColorEnd]
    ),
  ),
  child: ClipRect(
    clipBehavior: Clip.hardEdge,
    child: OverflowBox(
      maxHeight: screenHeight/3.5 +20,
      maxWidth: screenWidth/3.5 + 20,
      child:Container(
        decoration: BoxDecoration(
          color: Colors.white,
          shape: BoxShape.circle,
        ),
      )
    ),
  ),
);
Run Code Online (Sandbox Code Playgroud)

结果是

在此输入图像描述

有什么方法可以溢出小部件内的某些内容,使其看起来像是被剪裁的吗?

提前致谢!

Ken*_*ith 5

我找到了实现我想要的目标的方法,但仍然很困惑为什么OverFlowBox无法对齐。我认为这是因为尺寸OverFlowBox大于其父级,但当我将其更改为更小的尺寸时它仍然不起作用。

我使用了Stackand Positionedwidget 并将overflow堆栈的参数设置为overflow.clip

这是代码:

return Container(
  height: screenHeight/3.5,
  width: screenWidth/3.2,
  decoration: BoxDecoration(
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(10),
      topRight: Radius.circular(60),
      bottomLeft: Radius.circular(10),
      bottomRight: Radius.circular(10),
    ),
    gradient: LinearGradient(
      begin: FractionalOffset.topLeft,
      end: FractionalOffset.bottomRight,
      colors: [boxColorBegin, boxColorEnd]
    ),
  ),
  child: Stack(
    overflow: Overflow.clip,
    alignment: Alignment.topCenter ,
    children: <Widget>[
      Positioned(
        bottom: screenHeight / 8,
        right: screenWidth / 12,
        child: Container(
          width: screenWidth / 3.5,
          height: screenHeight / 3.5,
          decoration: BoxDecoration(
            color: Colors.white38,
            shape: BoxShape.circle,
          ),
        )
      )
    ],
  )
)
Run Code Online (Sandbox Code Playgroud)

结果是

在此输入图像描述

编辑

事实证明,您可以将参数用作Container剪辑器clipBehavior,并使用FractionalTranslation小部件作为子项来操纵白色圆圈的位置。感谢pskink的简单回答。

这是新代码

return Container(
  alignment: Alignment.topLeft,
  clipBehavior: Clip.antiAlias,
  height: screenHeight/3.5,
  width: screenWidth/3.2,
  decoration: BoxDecoration(
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(10),
      topRight: Radius.circular(60),
      bottomLeft: Radius.circular(10),
      bottomRight: Radius.circular(10),
    ),
    gradient: LinearGradient(
      begin: FractionalOffset.topLeft,
      end: FractionalOffset.bottomRight,
      colors: [boxColorBegin, boxColorEnd]
    ),
  ),
  child: FractionalTranslation(
    translation: Offset(-0.25, -0.5),
    child: Container(
      width: screenWidth / 3.5,
      height: screenHeight / 3.5,
      decoration: BoxDecoration(
        color: Colors.white38,
        shape: BoxShape.circle,
      ),
    )
  )
);
Run Code Online (Sandbox Code Playgroud)