[英]Flutter CheckboxListTile secondary widget function
Using the CheckboxListTile widget with an edit icon as the secondary widget. 使用带有编辑图标的CheckboxListTile小部件作为辅助小部件。
I want to be able to edit each item in the Checkbox list. 我希望能够编辑“复选框”列表中的每个项目。
!( https://ibb.co/m0Gc3Gx ) !( https://ibb.co/m0Gc3Gx )
What is a good way of adding a function to be able to edit each item in the CheckboxListTile. 添加功能的一种好方法是能够编辑CheckboxListTile中的每个项目。
Widget _buildItem(BuildContext context, int index) {
final remind = reminders[index];
return CheckboxListTile(
value: remind.isDone,
title: Text(remind.title + "-" + remind.message),
secondary: const Icon(Icons.edit),
controlAffinity: ListTileControlAffinity.leading,
onChanged: (bool isChecked) {
onRemindToggle(remind, isChecked);
},
);
}
There could be a better way of doing this. 可能会有更好的方法。 But giving a brief idea about how to achieve it is as follows:
但是,对实现方法的简要说明如下:
static String name = "John";
Map<String, bool> values = {
name: true,
};
Widget checkbox()
{
return ListView(
children: values.keys.map((String key) {
return new CheckboxListTile(
title: new Text(name),
value: values[key],
secondary: IconButton(
icon: Icon(Icons.edit),
onPressed: (){
setState(() {
name = "James";
});
print("Name is : $name");
},
),
controlAffinity: ListTileControlAffinity.leading,
onChanged: (bool value) {
setState(() {
values[key] = value;
});
},
);
}).toList(),
);
}
which would result into something like this . 这将导致弄成这样 。
And when edit icon is pressed the field changes from john to James. 当按下编辑图标时,字段从john变为James。 Similarly you can edit the code as per your need.
同样,您可以根据需要编辑代码。 Hope it helped:)
希望能有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.