如何根据bool值更改单个颜色-抖动( dart )

4szc88ey  于 2023-03-10  发布在  其他
关注(0)|答案(1)|浏览(105)

我想改变一个container的颜色取决于布尔值我已经保存.但当我改变容器的颜色它改变了所有容器的颜色,因为我的代码是指所有的容器,所以我怎么能只使一个容器的颜色改变这里是我的代码和一些额外的信息:

joined = false;

//when I click on a button it changes the value to true

...onPressed: (){Joined = true;}

//when Joined is true it should change the color to green

color: Joined ? Colors.blue : Colors.green),

//I also gave each container a key/id
//This is referencing a Firebase Database

People['key'] = snapshot.value;

//but when I write this code it makes ALL the container's colors green
//I have all the tools I just don't know how to write the code.

我试图在修改值时实现People['key']代码,但它不起作用,我也不确定如何编写代码。我还尝试在YouTube和Google上搜索,但没有太多信息可供参考。

vfh0ocws

vfh0ocws1#

使用Map,

Map<String. bool> joined = {};
    
...onPressed: (){joined[id] = true;}

color: (joined.containskey(id) && joined[id]) ? Colors.blue : Colors.green),

相关问题