[英]Error while rendering a CheckboxListTile widget in a Row widget in Flutter
[英]Flutter CheckboxListTile secondary widget function
使用帶有編輯圖標的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);
},
);
}
可能會有更好的方法。 但是,對實現方法的簡要說明如下:
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(),
);
}
這將導致弄成這樣 。
當按下編輯圖標時,字段從john變為James。 同樣,您可以根據需要編輯代碼。 希望能有所幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.