Is there any way to give gradient color to normal color property in flutter?

1.1k views Asked by At

I am using Bar Chart of fl_chart plugin. I want to give gradient color to bar graph. Below is the line where I want give color.

BarChartRodData(y: 12, color: Color(0xFF639ed1),width: 12)

But it is not possible to set gradient color to the ##color## property unless it is colors.

Is there any way to set gradient color to color property?? Please help me..

1

There are 1 answers

1
Asiri Hewage On

If you pass just one color, the solid color will be used, or if you pass more than one color, we use gradient mode to draw. then the gradientFrom, gradientTo and gradientColorStops

For an example ,

final List<Color> color = <Color>[];
        color.add(Colors.blue[50]);
        color.add(Colors.blue[100]);
        color.add(Colors.blue);


 final List<double> stops = <double>[];
    stops.add(0.0);
    stops.add(0.5);
    stops.add(1.0);

Please refer https://pub.dev/documentation/fl_chart/latest/fl_chart/BarChartRodData-class.html for BarChartRodData class variables