ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【Flutter 专题】116 图解 PhysicalModel & PhysicalShape 裁切小组件

2021-12-10 19:33:05  阅读:165  来源: 互联网

标签:return 裁切 80.0 color PhysicalShape width PhysicalModel child height


return ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: Container(width: 80.0, height: 80.0, child: Image.asset(‘images/icon_hzw01.jpg’)));
return Container(
width: 80.0, height: 80.0,
child: ClipOval(child: Image.asset(‘images/icon_hzw01.jpg’, fit: BoxFit.fill)));

// PhysicalModel
return PhysicalModel(
color: Colors.transparent,
shape: isCircle ? BoxShape.circle : BoxShape.rectangle,
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: Container(width: 80.0, height: 80.0, child: Image.asset(‘images/icon_hzw01.jpg’)));

2. color & shadowColor

color 对应 Widget 裁切的背景色,阴影效果是根据当前背景色展示,shadowColor 可以设置阴影颜色;

return PhysicalModel(
color: Colors.teal.withOpacity(0.6),
shape: isCircle ? BoxShape.circle : BoxShape.rectangle,
clipBehavior: Clip.antiAlias,
elevation: 6.0,
shadowColor: isCircle ? Colors.yellow : Colors.deepOrange,
borderRadius: BorderRadius.all(Radius.circular(20.0)),
child: Container(width: 80.0, height: 80.0, color: Colors.pink.withOpacity(0.2)));

PhysicalShape

源码分析

const PhysicalShape({
Key key,
@required this.clipper,
this.clipBehavior = Clip.none,
this.elevation = 0.0,
@require

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

d this.color,
this.shadowColor = const Color(0xFF000000),
Widget child,
})

分析源码可得,PhysicalShapeClipPath 类似,均是通过 clipper 方式自定义裁切方式;

案例尝试

小菜尝试裁切一个多边形图片,通过自定义 CustomClipper 来设置裁切样式;

return ClipPath(
clipBehavior: Clip.antiAlias,
clipper: PolygonClipper(10),
child: Container(width: 80.0, height: 80.0, child: Image.asset(‘images/icon_hzw01.jpg’)));

return PhysicalShape(
color: Colors.transparent,
clipBehavior: Clip.antiAlias,
clipper: PolygonClipper(10),
shadowColor: Colors.deepOrange,
elevation: 6.0,
child: Container(width: 80.0, height: 80.0, child: Image.asset(‘images/icon_hzw01.jpg’)));

class PolygonClipper extends CustomClipper {
final int num;
PolygonClipper(this.num);

@override
Path getClip(Size size) {
double radius = size.width * 0.5;
Path _path = Path();
var startX = size.width * 0.5 + radius * cos(2 * pi * 0 / num);
var startY = size.height * 0.5 + radius * sin(2 * pi * 0 / num);
_path.moveTo(startX, startY);
for (var i = 1; i <= num; i++) {
var newX = size.width * 0.5 + radius * cos(2 * pi * i / num);
var newY = size.height * 0.5 + radius * sin(2 * pi * i / num);
_path.lineTo(newX, newY);
}
_path.close();
return _path;
}
@override
bool shouldReclip(CustomClipper oldClipper) => true;
}
se();
return _path;
}
@override
bool shouldReclip(CustomClipper oldClipper) => true;
}

标签:return,裁切,80.0,color,PhysicalShape,width,PhysicalModel,child,height
来源: https://blog.csdn.net/m0_64604842/article/details/121863410

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有