【发布时间】:2020-08-22 06:46:28
【问题描述】:
我正在按照下面的图片进行操作,但是当我尝试制作那个白色气泡时遇到了一些困难。
我尝试过使用另一篇帖子Flutter mask a circle into a container 中的OverFlowBox 的方法,但我把圆圈卡在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,
),
)
),
),
);
结果是
有没有办法让小部件内部的东西溢出,让它看起来像被剪掉了?
提前致谢!
【问题讨论】:
-
如果你想让某个小部件溢出它的父级,那你为什么要使用剪辑呢?
-
因为我其实想剪掉溢出的部分
-
但如果您只想定位您的孩子,您根本不需要
OverflowBox:child: Container( alignment: Alignment.topLeft, clipBehavior: Clip.antiAlias, decoration: BoxDecoration( borderRadius: BorderRadius.circular(30), color: Colors.grey, ), child: FractionalTranslation( translation: Offset(-0.25, -0.5), child: Container( width: 200, height: 200, decoration: BoxDecoration( color: Colors.orange, shape: BoxShape.circle, ), ), ), ), -
我看到了,所以您可以使用
Container进行剪辑。我认为您的代码是最简单的代码,没有额外的Stack、ClipRRect或重复BorderRadius。你想留下答案吗? -
当然,欢迎您,顺便说一句,您也可以避免使用
FractionalTranslation而不是Alignment.topLeft使用Alignment(-1, -2)或其他东西,但是当使用FractionalTranslation时,您可以更精确地控制如何定位孩子小部件
标签: flutter