我想将“圆形头像”的一半着色为深蓝色,另一半着色为浅蓝色。我的意思是一半。我该如何实现?
就像他们一样 -
我试过了,但没有成功-
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFF040663),
Color(0xFF434599),
],
),
),
child: CircleAvatar(
backgroundColor: Colors.transparent,
radius: MediaQuery.of(context).size.height*0.045,
child: Icon(
icon,
size: size,
color: Colors.white,
),
),
),
有人可以告诉我如何编辑此代码,或告诉我实现此目标的新方法吗?
你快到了。您需要在渐变中重复一种颜色,并使用Stops属性获得清晰的渐变。
return Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.purple,
Colors.purple,
Colors.blue,
],
stops: [
0, 0.5, 0.5
]
),
),
child: Icon(
Icons.camera,
size: 32,
color: Colors.white,
),
);
结果如下:
有关更多信息,请参阅Stops属性文档:https : //api.flutter.dev/flutter/painting/Gradient/stops.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句