【发布时间】:2021-09-23 17:25:26
【问题描述】:
首先,我有 CheckList 类,其中我有列表 checkLists 和许多其他变量,如名称、位置等,在这个列表中我有 CheckList 对象。
所以在 Dismissible 键中我通过了 CheckList.checkLists[index] 但我得到了这个错误
不能将参数类型“CheckList”分配给参数类型“Key”
Scaffold(
body: Container(
padding: EdgeInsets.all(14.0),
child: ListView.separated(
itemCount: CheckList.checkLists.length,
itemBuilder: (BuildContext Context, int index){
return Dismissible(
key: CheckList.checkLists[index],
child: InkWell(
),
);
},
separatorBuilder: (BuildContext context, int index) {
return Container(
height: 14,
);
}),
),
);
我需要将什么传递给密钥?
第二个问题
ListView 中的项目必须如下所示。这是我应用程序中其他 ListView 的项目,但我需要与新 ListView 项目中的其他数据相同
我的 Dismissble 项目会用这种类型的代码正常关闭吗?
Scaffold(
body:
Container(
padding: EdgeInsets.all(14.0),
child: ListView.separated(
itemCount: CheckList.checkListtemplateXmlList.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: (){
CheckList checkList = CheckList();
CheckList.addCheckList(index,checkList);
showDialog(context: context, builder: (BuildContext context){
return AlertDialog(
title: Text('Добавить описание'),
content: TextField(
onChanged: (String value) async{
checkList.description = value;
},
),
actions: [
ElevatedButton(onPressed: () async{
await checkList.writeToFile();
setState(() {
CheckList.checkLists.add(checkList);
});
Navigator.pushNamedAndRemoveUntil(context, '/',(route) => false );
},
child: Text('Добавить'))
],
);
});
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Color.fromARGB(255, 141, 166, 255), width: 1),
borderRadius: BorderRadius.circular(10)),
width: 50,
height: 80,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"${CheckList.checkListTempaltexmlNameList[index]}",
style: TextStyle(fontSize: 40),
)
],
),
),
);
},
separatorBuilder: (BuildContext context, int index) {
return Container(
height: 14,
);
}),
),
);
【问题讨论】:
-
我回答了你的第一个问题。为清楚起见,您应该编辑第二个问题并将其移至新问题。