【发布时间】:2022-01-18 14:44:51
【问题描述】:
我正在尝试更改映射列表中所选项目的颜色。以下代码仅更改最后一个选定项目的颜色,但我想更改所有选定项目的颜色。谢谢。
String selectedSport = '';
Wrap(
children: List1.entries.map<Widget>((entry) {
return FittedBox(
fit: BoxFit.fill,
child: Container(
margin: const EdgeInsets.all(8.0),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 7),
decoration: BoxDecoration(
color: selectedSport == entry.key? AppColor.blueColor.withOpacity(0.3): Colors.white ,
borderRadius: BorderRadius.all(Radius.circular(20)),
border: Border.all(color: AppColor.blueColor)),
child: Center(
child: GestureDetector(
onTap: () {
setState(() {
selectedSport = entry.key;
});
},
child: Text(entry.key, style: GoogleFonts.inter(
fontSize: 14,
fontWeight: FontWeight.w600,
color: AppColor.blueColor),
),
),
),
),
);
}).toList(),
),
Map<String, bool> List1 = {
'Bubble Football ⚽': false,
'Futsal ????': false,
'Beach Volleyball ????': false,
'Volleyball ????': false,
'Dodgeball ????': false,
'Rugby ????': false,
'American Footbal ????': false,
'Korftbal ????': false,
'Netbal ⚾': false,
'Padel ⚒': false,
'Table Tennis ????': false,
}
【问题讨论】: