Closed emvaized closed 4 years ago
SliverExpandableList(
builder: SliverExpandableChildDelegate<String, Section>(
sectionList: sectionList,
headerBuilder: _buildHeader,
itemBuilder: (context, section, item, index) => Dismissible(
key: Key(item),
onDismissed: (DismissDirection direction) {
section.getItems().remove(item);
},
child: ListTile(
leading: CircleAvatar(
child: Text("$index"),
),
title: Text(item),
),
),
),
),
@tp7309 Unfortunately, with your implementation I get this error somehow:
A dismissed Dismissible widget is still part of the tree.
Make sure to implement the onDismissed handler and to immediately remove the Dismissible widget from the application once that handler has fired.
Sorry, example fixed:
SliverExpandableList(
builder: SliverExpandableChildDelegate<String, Section>(
sectionList: sectionList,
headerBuilder: _buildHeader,
itemBuilder: (context, section, item, index) => Dismissible(
key: Key(item),
onDismissed: (DismissDirection direction) {
setState(() {
section.getItems().remove(item);
});
},
child: ListTile(
leading: CircleAvatar(
child: Text("$index"),
),
title: Text(item),
),
),
),
),
@tp7309 Still get the RangeError :((
Maybe that's because item
in my case is a String 'item$index', which is never used in a resulting widget from itemBuilder
?
sectionList has List<item>, you need remove item object where from itemBuilder: (context, section, item, index). Try run example run normally first, then test you project.
@tp7309 And section's header will be removed with item as well?
I found the solution of my problem. Just had to replace
for (int i = 0; i <= 10; i++) {
var section = Section()
..expanded = true
..header = 'header$i'
..items = List.generate(1, (index) => "item$i");
sections.add(section);
}
in getExampleSections()
with this:
data.forEach((i) {
var section = Section()
..expanded = true
..header = 'header$i'
..items = List.generate(1, (index) => "item$i");
sections.add(section);
});
The problem was in hard-coded amount of 10 sections 😅 Thanks for all help!
How to properly remove section from screen in
onDismissed()
callback of Dismissible widget? I tried to callwidget.fetchedData.removeAt(position)
, but it seems to fail, resulting in 'RangeError (index)'.