tp7309 / flutter_sticky_and_expandable_list

粘性头部与分组列表Sliver实现 Build a grouped list, which support expand/collapse section and sticky headers, support use it with sliver widget.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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),
                      );
                    }),
              );

}
}

And here is the error
Screenshot from 2020-08-24 13-34-19

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.