我给容器上色,上面有一个 linearGradient。
Container(
padding: EdgeInsets.only(left: 7.0),
decoration: BoxDecoration(
border: Border.all(
width: 1,
color: Colors.black12,
),
borderRadius: BorderRadius.all(
Radius.circular(7.0)
),
boxShadow: [
BoxShadow(
offset: Offset(1, 3),
blurRadius: 5.0,
color: Colors.grey,
)
],
gradient: LinearGradient(
colors: [
_changeColorBrightness(widget.item.color, 0.1),
_changeColorBrightness(widget.item.color, -0.1),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
),
Run Code Online (Sandbox Code Playgroud)
为了获得渐变的颜色,我将两侧的颜色变亮/变暗:
Color _changeColorBrightness(Color color, double deltaValue) {
HSVColor hsvColor = HSVColor.fromColor(color);
double newValue = hsvColor.value + deltaValue;
if (newValue < 0.0) {
newValue = 0.0;
} else if (newValue > 1.0) {
newValue …Run Code Online (Sandbox Code Playgroud) flutter ×1