I am a beginner in Filter and I am typing these words with Google translator, my English is not good, please help and thank you very much.
Description of the problem
I have four clickable containers. I would like when the user clicks on them, only the background color of the current container will be changed to red, and the rest of the three containers will have their background color changed to blue.
I tried several times and for five days I couldn’t do anything unfortunately..
Where I used a variable to set the col value to be white as an initial value
This is the problem part
GestureDetector(
onTap: () {
setState(() {
(col == Colors. white) ?col = Colors. red:col = Colors. blue;
});
},
child: Container(
alignment: Alignment. topLeft,
decoration: BoxDecoration(
color: color,
),
child: Text(
'S',
),
),
),`
I just want when clicking on the container, it changes color with a characteristic that differs from other containers
2
Answers
You need to assign color with ternary operator like
Or
But if you are using single variable for all three container, it will change them all. Try using List instead.
If it is about selecting single container, it will
my solution by using a list view I have 5 containers when clicking on the container widget will update the current Index and change color
Have Nice Day 🙂