user_detail_model.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'dart:math';
  2. import 'package:sport/bean/forum.dart';
  3. import 'package:sport/bean/post.dart';
  4. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  5. import 'package:sport/provider/social_detail_model.dart';
  6. import 'package:sport/services/api/inject_api.dart';
  7. class UserDetailModel extends SocialDetailModel with InjectApi {
  8. int type = 0;
  9. String id;
  10. Forum forum;
  11. String _sortBy = "created_at";
  12. UserDetailModel(this.id) : super(0);
  13. @override
  14. Future<List> loadData({int pageNum = 1}) async {
  15. List items = [];
  16. if (pageNum == 1) {
  17. var top = await api.getPostUserTopSubjects(id);
  18. if (top?.results?.isNotEmpty == true) {
  19. top.results.forEach((element) {element.isUserTop = "1";});
  20. items.addAll(top.results);
  21. }
  22. }
  23. // 这里修改了下 论坛...
  24. var page = handlePage(await api.getPostListByUser(id, page: max(pageNum, 1), sortBy: _sortBy, removeTop: 1));
  25. if (page?.isNotEmpty == true) {
  26. items.addAll(page);
  27. }
  28. return items;
  29. }
  30. forumBy(Forum forum) {
  31. this.forum = forum;
  32. // forumId = forum?.forumId;
  33. initData();
  34. }
  35. sortBy(String name) {
  36. if (name == "时间倒序") {
  37. _sortBy = "created_at";
  38. } else if (name == "点赞最多") {
  39. _sortBy = "like_count";
  40. } else if (name == "评论最多") {
  41. _sortBy = "comment_count";
  42. }
  43. initData();
  44. }
  45. }