从List< Widget>中删除索引明智的CustomWidget.在Flutter [英] Remove Index wise CustomWidget from List<Widget> in Flutter
问题描述
我最初在Column中没有Widget的空列表.现在,在其他"小部件上,单击我要在_contactItems
I have initially empty list of Widget in Column. Now on Other widget click I am adding new Custom Widget in _contactItems
Column(
children: _contactItems,
)
List<Widget> _contactItems = new List<CustomWidget>();
_contactItems.add(newCustomWidget(value));
现在假设我有6条记录(列"中有6个自定义小部件").我正在尝试删除索引明智的记录(例如.我要删除第3条记录,然后删除第1条记录.列小部件(动态小部件)应更新为_contactItems,在setState()
中更新)
Now Suppose I have 6 Records (6 Custom Widgets in Column). I am trying to remove index wise records (Example. I am removing 3rd record then 1st record. Column Widgets (dynamic widgets) should be updated as _contactItems updating in setState()
)
现在,在 CustomWidget 上单击我正在从列中删除特定的 CustomWidget ".
Now on CustomWidget click I am removing that particular CustomWidget from Column.
setState(() {
_contactItems.removeAt(index);
});
也尝试过
_contactItems.removeWhere((item) {
return item.key == _contactItems[index].key;
});
推荐答案
尝试一下(假设您的Column小部件键具有这种格式):
Try this (assuming that your Column widget keys have this format):
setState(() {
this._contactItems.removeWhere((contact) => contact.key == Key("index_$index"));
});
如果这不能解决您的问题,也许我们需要更多信息.
If this doesn't solve your issue, maybe we'll need more info.
这篇关于从List< Widget>中删除索引明智的CustomWidget.在Flutter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!