fluttergradientflutter-custompainterflutter-custompaint

Flutter - Hard color stop in linear gradient


I'm using CustomPaint to make a custom shape and I want to apply a color gradient but with hard color stops. Without color transitions.
PS:I cannot use different Paints instead of gradient because of the custom shape.

I checked the documentation and couldn't find anything. Is it impossible? Or is there any other workarounds? Thanks!


Solution

  • Okay I figured it out myself, I use Gradient.linear as the shader for custom paint. I noticed that it only blends colors when there is a big gap in stops. So I put my colors and stops like this.

    Colors | Stop

    Green 0.2
    Green 0.201
    Blue 0.5
    Blue 0.501
    Yellow 1

    Now the color stops are hard.

    Here's a preview of before and after |enter image description here enter image description here