CustomAdapter

  • Custom implementation of large Cell in LisView.
  • The Factors of the Adapter are similar to the Component's. The difference is that the view part of the Adapter returns a ListAdapter.
  • Sample Code
  1. class CommentAdapter extends Adapter<CommentState> {
  2. CommentAdapter()
  3. : super(
  4. adapter: buildCommentAdapter,
  5. effect: buildCommentEffect(),
  6. reducer: buildCommentReducer(),
  7. );
  8. }
  9.  
  10. ListAdapter buildCommentAdapter(CommentState state, Dispatch dispatch, ViewService service) {
  11. final List<IndexedWidgetBuilder> builders = Collections.compact(<IndexedWidgetBuilder>[]
  12. ..add((BuildContext buildContext, int index) =>
  13. _buildDetailCommentHeader(state, dispatch, service))
  14. ..addAll(_buildCommentViewList(state, dispatch, service))
  15. ..add(isEmpty(state.commentListRes?.items)
  16. ? (BuildContext buildContext, int index) =>
  17. _buildDetailCommentEmpty(state.itemInfo, dispatch)
  18. : null)
  19. ..add(state.commentListRes?.getHasMore() == true
  20. ? (BuildContext buildContext, int index) => _buildLoadMore(dispatch)
  21. : null));
  22. return ListAdapter(
  23. (BuildContext buildContext, int index) =>
  24. builders[index](buildContext, index),
  25. builders.length,
  26. );
  27. }
  28.  
  29. ///builds