Using the CheckboxListTile widget with an edit icon as the secondary widget.
I want to be able to edit each item in the Checkbox list.
What is a good way of adding a function to be able to edit each item in the 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. Similarly you can edit the code as per your need. Hope it helped:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.