Remove Index wise CustomWidget from List<Widget> in Flutter
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.
Harsh Bhavsar
Hello, I am Harsh Bhavsar. Having 4+ experience in mobile development and 1+ year of experience in flutter development. • In mobile development, I have worked with Image-Video Editing Apps, Survery Apps, Chat Apps, Location-Map based Apps, Various management Apps, BLE related Apps etc. About my area work in flutter. • I have worked with Flutter's UI/UX , Google Maps, Couchbase, Socket connection, Sync gateways, Localizations, Customised plateform specific plugins, plateform specfic codes/views, Firestores with flutter, Chat with XMPP(native Android) and openfire, FFmpeg for Image-Video processing etc. We have worked with MVC, BLoc and Flux design pattern/ state management based on project requirements.
Updated on December 08, 2022Comments
-
Harsh Bhavsar over 1 year
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));
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()
)Now on CustomWidget click I am removing that particular CustomWidget from Column.
setState(() { _contactItems.removeAt(index); });
Also tried with
_contactItems.removeWhere((item) { return item.key == _contactItems[index].key; });