[英]Flutter how to paint custom gradients
I recently experienced a problem when I was trying to create following AppBar with gradient.我最近在尝试创建带有渐变的 AppBar 时遇到了一个问题。
When I tried to replicate this design in flutter with the colors rose = Color(0xFFec15ee), purple = Color(0xFF8561f5) and blue = Color(0xFF1eaefc) and set the alignment property accordingly it somehow gave me not the expected result当我尝试用玫瑰色 = Color(0xFFec15ee), Purple = Color(0xFF8561f5) 和 blue = Color(0xFF1eaefc) 复制此设计并相应地设置对齐属性时,它以某种方式给了我预期的结果
BoxDecoration(
gradient: LinearGradient(
colors: [
AppColors.roseGradientColor,
AppColors.purpleInAppGradientColor,
AppColors.blueInAppGradientColor
],
stops: [
0.0,
0.05,
1.0
],
begin: Alignment.bottomLeft,
end: Alignment.topRight
),
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(25),bottomRight: Radius.circular(25))
)
Just imagine the opacity wouldnt be there.想象一下不透明度不会在那里。 As you can see I only want the rose to be aligned at the bottomLeft and not to expand up to topLeft as shown in the example.如您所见,我只希望玫瑰在左下角对齐,而不是像示例中所示那样向上扩展到左上角。
My question how can I do that.我的问题我该怎么做。 There must a way to do that within CustomPainter yet I haven't found the right way.必须有一种方法可以在 CustomPainter 中做到这一点,但我还没有找到正确的方法。
pskinks comment was right and I totally overlooked this option. pskinks 评论是正确的,我完全忽略了这个选项。 Using the Alignment(x,y) was the key here.使用 Alignment(x,y) 是这里的关键。
Here is the solution for my above problem.这是我上述问题的解决方案。
BoxDecoration(
gradient: LinearGradient(
colors: [
AppColors.roseGradientColor,
AppColors.purpleInAppGradientColor,
AppColors.blueInAppGradientColor
],
begin: Alignment(-0.7,12),
end: Alignment(1,-2),
),
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(25),bottomRight: Radius.circular(25))
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.