我有一个 Container
ClipPath
内的小部件它使用 CustomClipper
.一切正常,我有所需的小部件形状。
但是,我找不到为这个自定义形状的 Widget 制作阴影的方法。
另外,我想要一个自动跟随这个自定义小部件边缘的轮廓(边框)。
再次没有运气。我试过 BoxDecoration:border
, BoxDecoration:boxShadow
, ShapeDecoration:shape
, ShapeDecoration:shadows
, Material:Elevation
, 等等..
最佳答案
基于@Bohdan Uhrynovskiy,我进一步调查并提出了这个解决方案:
CustomPaint(
painter: BoxShadowPainter(),
child: ClipPath(
clipper: MyClipper(), //my CustomClipper
child: Container(), // my widgets inside
)));
class BoxShadowPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Path path = Path();
// here are my custom shapes
path.moveTo(size.width, size.height * 0.14);
path.lineTo(size.width, size.height * 1.0);
path.lineTo(size.width - (size.width *0.99) , size.height);
path.close();
canvas.drawShadow(path, Colors.black45, 3.0, false);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
您必须需要在
paint()
中提供您自己的自定义路径BoxShadowPainter
的方法
关于dart - 如何为 CustomClipper 创建的小部件制作合适的边框和阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54753355/