Search code examples
fluttershadergradientlinear-gradients

How to do a Gradient effect from topLeft to botttomRgiht in Flutter Shader?


Hy everyone,

I need to know, how do I can create so a Gradient colors from topLeft to bottomRight withhin a shader in flutter like in example 2 in this image?

enter image description here

I tried with this mini shader code to do this, but it still doesn't working for me.

final Shader linearGradient = LinearGradient(
      colors: <Color>[
        Color(0xff002fff),
        Color(0xff00f4ff),
      ],
    ).createShader(Rect.fromCircle(center: Offset(200, 0), radius: 150));

Could anybody have a ideea, how can this be created? Or it's not impossible right now in Flutter 🤷‍♂️.


Solution

  • You can use begin and end properties of LinearGradient.

    Ex:

      LinearGradient(
         begin: Alignment.topLeft,
         end: Alignment.bottomRight,
         colors: <Color>[
         Color(0xff002fff),
         Color(0xff00f4ff),
         ],
     ),