social_detail_model.dart 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. void swtichTab(int type) async {
  12. this._type = type;
  13. initData();
  14. }
  15. void setKeyword(String kw) async {
  16. this._type = 100;
  17. this._kw = kw;
  18. initData();
  19. }
  20. void setForumId(String forumId) async {
  21. this._type = 100;
  22. this._forumId = forumId;
  23. initData();
  24. }
  25. void setForumIdAndOrigin(int type, String? forumId, String? isOfficial) {
  26. this._forumId = forumId;
  27. this._isOfficial = isOfficial;
  28. this._type = type;
  29. initData();
  30. }
  31. @override
  32. Future<List> loadData({int pageNum = 1}) async {
  33. List results = [];
  34. switch (_type) {
  35. case 100:
  36. results = handlePage(await api.getPostList(
  37. kw: _kw,
  38. page: max(1, pageNum),
  39. forumId: _forumId,
  40. isOfficial: _isOfficial));
  41. break;
  42. // 第四个变成公共了...
  43. case 4:
  44. results = handlePage(await api.getPostListByOfficial(
  45. page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
  46. break;
  47. // case 4:
  48. // SharedPreferences prefs = await SharedPreferences.getInstance();
  49. // results = handlePage(await api.getPostListByUser(
  50. // prefs.getInt("id").toString(),
  51. // forumId: _forumId,
  52. // page: max(1, pageNum)));
  53. // break;
  54. case 3:
  55. results = handlePage(await api.getPostList(
  56. isGood: 1,
  57. page: max(1, pageNum),
  58. forumId: _forumId,
  59. isOfficial: _isOfficial));
  60. break;
  61. case 2:
  62. results = handlePage(await api.getPostList(
  63. page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
  64. break;
  65. case 1:
  66. SharedPreferences prefs = await SharedPreferences.getInstance();
  67. results = handlePage(
  68. await api.getPostListByFollow(prefs.getInt("id").toString(),
  69. page: max(1, pageNum),
  70. forumId: _forumId,
  71. isOfficial: _isOfficial),
  72. );
  73. break;
  74. default:
  75. results = handlePage(await api.getPostListByHot(
  76. page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
  77. break;
  78. }
  79. return results;
  80. }
  81. }