【发布时间】:2021-12-10 08:13:00
【问题描述】:
我有一个默认值为 false 的项目列表,我正在使用复选框将所选项目更改为 true,然后我尝试将 true 键添加到共享首选项中的列表中,但我是收到“参数类型“字符串”无法分配给参数类型“列表”的错误消息 谢谢大家
class BallGames extends StatefulWidget {
@override
BallGamesState createState() => new BallGamesState();
}
class BallGamesState extends State {
Map<String, bool> List = {
'Bubble Football ⚽': false,
'Futsal ????': false,
'Beach Volleyball ????': false,
'Volleyball ????': false,
'Dodgeball ????': false,
'Rugby ????': false,
'American Footbal ????': false,
'Korftbal ????': false,
'Netbal ⚾': false,
};
getItems() {
List.forEach((key, value) async {
if (value == true) {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setStringList('selectedGames', key); //the 'key' is underline as the error value
// the error message: 'The argument type 'String' can't be assigned to the parameter type 'List<String>''
}
});
【问题讨论】: