I tried to draw a circle sliced and painted based on a dynamic list. I have a back-end that returns a list of group of colors, each group of color must to paint a full circle and each color must to be a slice of the circle.
The back-end response is like this:
"suggestionList": [
{
"id": 0,
"name": "Analogas",
"colors": [
{
"alpha": 255,
"red": 0,
"green": 255,
"blue": 127
},
{
"alpha": 255,
"red": 1,
"green": 255,
"blue": 0
},
{
"alpha": 255,
"red": 0,
"green": 255,
"blue": 255
}
]
},
{
"id": 1,
"name": "Complementares",
"colors": [
{
"alpha": 255,
"red": 0,
"green": 255,
"blue": 127
},
{
"alpha": 255,
"red": 255,
"green": 0,
"blue": 128
}
]
},
]
I would like to change colors based group button what I clicked:
Exemplo of circle paint based on color group
Unfortunately I can't pass the list to the paint method dynamically as a parameter, when I fix a sample list on the method, it works fine.
@override
void paint(Canvas canvas, Size size) {
List<ColorDTO> colorList = [];
colorList.add(ColorDTO(alpha: 255, red: 0, green: 255, blue: 127));
colorList.add(ColorDTO(alpha: 255, red: 127, green: 0, blue: 255));
colorList.add(ColorDTO(alpha: 255, red: 255, green: 127, blue: 0));
double wheelSize = 100;
int nbElem = colorList.length;
double radius = (2 * pi) / nbElem;
for (int i = 0; i < colorList.length; i++) {
canvas.drawPath(
getWheelPath(wheelSize, radius * i, radius),
getColoredPaint(Color.fromARGB(colorList[i].alpha, colorList[i].red,
colorList[i].green, colorList[i].blue)));
}
}
How can I do this?