user_detail_model.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'dart:math';
  2. import 'package:sport/bean/forum.dart';
  3. import 'package:sport/provider/social_detail_model.dart';
  4. import 'package:sport/services/api/inject_api.dart';
  5. class UserDetailModel extends SocialDetailModel with InjectApi {
  6. int type = 0;
  7. String id;
  8. Forum? forum;
  9. String _sortBy = "created_at";
  10. UserDetailModel(this.id) : super(0);
  11. @override
  12. Future<List> loadData({int pageNum = 1}) async {
  13. List items = [];
  14. if (pageNum == 1) {
  15. var top = await api.getPostUserTopSubjects(id);
  16. if (top.results.isNotEmpty == true) {
  17. top.results.forEach((element) {
  18. element.isUserTop = "1";
  19. });
  20. items.addAll(top.results);
  21. }
  22. }
  23. // 这里修改了下 论坛...
  24. var page = handlePage(await api.getPostListByUser(id, page: max(pageNum, 1), forumId: this.forum?.forumId, 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. }