Cannot use custom model as ExpandableListSection Type
ydhnwb opened this issue · comments
I want to create sectioned list with String as header title and BoardWithCategory as the child
Here is my code
BoardWithcategory model that i want to use as child
class BoardWithCategory {
final Board board;
final BoardCategoryData boardCategoryData;
BoardWithCategory(this.board, this.boardCategoryData);
}
The board section,
class BoardSection implements ExpandableListSection<BoardWithCategory> {
bool isExpanded;
List<BoardWithCategory> boardWithCategory = List();
String title;
@override
List<BoardWithCategory> getItems() => boardWithCategory;
@override
bool isSectionExpanded() => isExpanded;
@override
void setSectionExpanded(bool expanded) {
this.isExpanded = expanded;
}
}
How I use this in a page
BlocConsumer.....{
builder: (context, state){
return SliverExpandableList(
builder: SliverExpandableChildDelegate<String, BoardSection>(
sectionList: _sectionList,
headerBuilder: _buildHeaderList,
controller: _controller,
itemBuilder: (context, sectionIndex, itemIndex, index) {
BoardWithCategory item = _sectionList[sectionIndex]
.boardWithCategory[itemIndex];
return ListTile(
leading: CircleAvatar(
child: Text("$index"),
),
title: Text(item.boardCategoryData.name),
);
}),
);
}
}
The error says
'BoardSection' doesn't extend 'ExpandableListSection'.
Try using a type that is or is a subclass of 'ExpandableListSection'
I already extends the BoardSection with ExpandableListSection not ExpandableListSection,
in the documentation it said that I need diamond interface , for this case im not using String as my model class but I get this error
*I have found the solution :)
I will add more comments here :)
I thought the first param in diamond interface inside SliverExpandbleChildDelegate<XXX, SomeAection> is the header.