CustomAdapter

  • 对大 Cell 的自定义实现
  • 要素和 Component 类似,不一样的地方是 Adapter 的视图部分返回的是一个 ListAdapter
  • 示例代码
  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