如何在Flutter中向ClipOval添加阴影?

编程入门 行业动态 更新时间:2024-10-21 06:30:18
本文介绍了如何在Flutter中向ClipOval添加阴影?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在努力使新应用成为初学者.因此,在事物上添加阴影对我来说是全新的.

I have been trying to make a new app being a beginner. So, adding shadows to things is completely new to me.

所以,以下是我的代码:

So, Following is my code:

Container( child: Row( mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[ ClipOval( child: Material( color: Colors.white, // button color child: InkWell( // splashColor: Colors.red, // inkwell color child: SizedBox( width: 46, height: 46, child: Icon(Icons.menu,color: Colors.red,),), onTap: () {}, ), ), ), ], ), ),

以下是模拟:

推荐答案

您可以创建自己的自定义剪切器

class CustomClipperOval extends CustomClipper<Rect> { @override Rect getClip(Size size) { return Rect.fromCircle( center: new Offset(size.width / 2, size.width / 2), radius: size.width / 2 + 3); } @override bool shouldReclip(CustomClipper<Rect> oldClipper) { return false; } } class ClipOvalShadow extends StatelessWidget { final Shadow shadow; final CustomClipper<Rect> clipper; final Widget child; ClipOvalShadow({ @required this.shadow, @required this.clipper, @required this.child, }); @override Widget build(BuildContext context) { return CustomPaint( painter: _ClipOvalShadowPainter( clipper: this.clipper, shadow: this.shadow, ), child: ClipRect(child: child, clipper: this.clipper), ); } } class _ClipOvalShadowPainter extends CustomPainter { final Shadow shadow; final CustomClipper<Rect> clipper; _ClipOvalShadowPainter({@required this.shadow, @required this.clipper}); @override void paint(Canvas canvas, Size size) { var paint = shadow.toPaint(); var clipRect = clipper.getClip(size).shift(Offset(0, 0)); canvas.drawOval(clipRect, paint); } @override bool shouldRepaint(CustomPainter oldDelegate) { return true; } }

然后使用它

ClipOvalShadow( shadow: Shadow( color: Colors.amber, offset: Offset(1.0, 1.0), blurRadius: 2, ), clipper: CustomClipperOval(), child: ClipOval( child: Material( color: Colors.white, // button color child: InkWell( // splashColor: Colors.red, // inkwell color child: Container( width: 46, height: 46, child: Icon( Icons.menu, color: Colors.black, ), ), onTap: () {}, ), ), ), ),

结果将是

更多推荐

如何在Flutter中向ClipOval添加阴影?

本文发布于:2023-11-12 03:55:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580446.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阴影   中向   如何在   Flutter   ClipOval

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!