flutter的组件裁剪代码片
Easul Lv4
折叠代码块DART 复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
Widget avatar = Image.asset(
"assets/imgs/wakuwaku.jpg",
fit: BoxFit.fitHeight,
width: 80.0,
height: 80.0,
);

// 不剪裁
avatar,
// 剪裁为圆形
ClipOval(child: avatar),
// 剪裁为圆角矩形
ClipRRect(
borderRadius: BorderRadius.circular(5.0),
child: avatar,
),

// 宽度设为原来宽度一半,另一半会显示,但会溢出,下边的文字会盖到上边
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Align(
alignment: Alignment.topLeft,
widthFactor: .5,
child: avatar,
),
Text(
"你好世界",
style: TextStyle(color: Colors.green),
)
],
),
// 将溢出部分剪裁
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipRect(
child: Align(
alignment: Alignment.topLeft,
widthFactor: .5, //宽度设为原来宽度一半
child: avatar,
),
),
Text("你好世界", style: TextStyle(color: Colors.green))
],
),
 评论
来发评论吧~
Powered By Valine
v1.5.2