Reputation: 29
I'm creating a table where the values are placed according to a list, but I want the color of each cell in the table to be varied between two different colors, I would like to know if there is any way to do this, using BoxDecoration as shown below
String color = "0xFFE8CFA7";
Container(
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 6),
decoration: new BoxDecoration(
color: Color(color),
),
child: Column(
children: previsao
.map((e) => Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
width: 104,
child: Text("${e.diaSemana}",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500)),
),
Text("T", style: TextStyle(fontSize: 18)),
Text("${e.tempMin}°",
style: TextStyle(fontSize: 18)),
Text("${e.tempMax}°",
style: TextStyle(fontSize: 18)),
],
))
.toList())
Upvotes: 1
Views: 197
Reputation: 9166
First, declare an int variable like this:
int index = 0;
Then in the color
property of the widget which you have multiples of it, you can set it like this:
color: (index++) % 2 == 0 ? Colors.red : Colors.blue,
This will result in a different colors for each widget like this:
Upvotes: 1