Flutter how to paint custom gradients
pskinks comment was right and I totally overlooked this option. Using the Alignment(x,y) was the key here.
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))
)
Christian X
Updated on December 18, 2022Comments
-
Christian X over 1 year
I recently experienced a problem when I was trying to create following AppBar with gradient.
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
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.
-
pskink about 4 yearsinsetead of
Alignment.topRight
useAlignment
that is far abovetop
- seeAlignment(double, double)
constructor
-
-
pskink about 4 yearsok, but why
-0.7
inbegin
alignment? why not-1
?-1
is for 'left" -
Christian X about 4 yearsI gotta be honest, I tested the design with -1, -5, -10, -0.2, -0.5 and so on and I found -0.7 to be the closest at the design I want. This value was 100% found through trial and error ;)
-
pskink about 4 yearsthe most important is that final result looks ok ;-)