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. ListAdapter buildCommentAdapter(CommentState state, Dispatch dispatch, ViewService service) {
  10. final List<IndexedWidgetBuilder> builders = Collections.compact(<IndexedWidgetBuilder>[]
  11. ..add((BuildContext buildContext, int index) =>
  12. _buildDetailCommentHeader(state, dispatch, service))
  13. ..addAll(_buildCommentViewList(state, dispatch, service))
  14. ..add(isEmpty(state.commentListRes?.items)
  15. ? (BuildContext buildContext, int index) =>
  16. _buildDetailCommentEmpty(state.itemInfo, dispatch)
  17. : null)
  18. ..add(state.commentListRes?.getHasMore() == true
  19. ? (BuildContext buildContext, int index) => _buildLoadMore(dispatch)
  20. : null));
  21. return ListAdapter(
  22. (BuildContext buildContext, int index) =>
  23. builders[index](buildContext, index),
  24. builders.length,
  25. );
  26. }
  27. ///builds