social_detail_model.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'dart:math';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  4. import 'package:sport/services/api/inject_api.dart';
  5. class SocialDetailModel extends ViewStateRefreshListModel with InjectApi {
  6. int _type = 0;
  7. String? _forumId;
  8. String? _kw;
  9. String? _isOfficial;
  10. SocialDetailModel(this._type);
  11. SocialDetailModel.forum(this._type, this._forumId);
  12. void swtichTab(int type) async {
  13. this._type = type;
  14. initData();
  15. }
  16. void setKeyword(String kw) async {
  17. this._type = 100;
  18. this._kw = kw;
  19. initData();
  20. }
  21. void setForumId(String? forumId) async {
  22. this._type = 100;
  23. this._forumId = forumId;
  24. initData();
  25. }
  26. void setForumIdAndOrigin(int type, String? forumId, String? isOfficial) {
  27. this._forumId = forumId?.isNotEmpty == true? forumId : null;
  28. this._isOfficial = isOfficial?.isNotEmpty == true? isOfficial : null;
  29. this._type = type;
  30. initData();
  31. }
  32. @override
  33. Future<List> loadData({int pageNum = 1}) async {
  34. List results = [];
  35. switch (_type) {
  36. case 100:
  37. results = handlePage(await api.getPostList(
  38. kw: _kw,
  39. page: max(1, pageNum),
  40. forumId: _forumId,
  41. isOfficial: _isOfficial));
  42. break;
  43. // 第四个变成公共了...
  44. case 4:
  45. results = handlePage(await api.getPostListByOfficial(
  46. page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
  47. break;
  48. // case 4:
  49. // SharedPreferences prefs = await SharedPreferences.getInstance();
  50. // results = handlePage(await api.getPostListByUser(
  51. // prefs.getInt("id").toString(),
  52. // forumId: _forumId,
  53. // page: max(1, pageNum)));
  54. // break;
  55. case 3:
  56. results = handlePage(await api.getPostList(
  57. isGood: 1,
  58. page: max(1, pageNum),
  59. forumId: _forumId,
  60. isOfficial: _isOfficial));
  61. break;
  62. case 2:
  63. results = handlePage(await api.getPostList(
  64. page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
  65. break;
  66. case 1:
  67. SharedPreferences prefs = await SharedPreferences.getInstance();
  68. results = handlePage(
  69. await api.getPostListByFollow(prefs.getInt("id").toString(),
  70. page: max(1, pageNum),
  71. forumId: _forumId,
  72. isOfficial: _isOfficial),
  73. );
  74. break;
  75. default:
  76. results = handlePage(await api.getPostListByHot(
  77. page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
  78. break;
  79. }
  80. return results;
  81. }
  82. }