123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import 'dart:math';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
- import 'package:sport/services/api/inject_api.dart';
- class SocialDetailModel extends ViewStateRefreshListModel with InjectApi {
- int _type = 0;
- String? _forumId;
- String? _kw;
- String? _isOfficial;
- SocialDetailModel(this._type);
- SocialDetailModel.forum(this._type, this._forumId);
- void swtichTab(int type) async {
- this._type = type;
- initData();
- }
- void setKeyword(String kw) async {
- this._type = 100;
- this._kw = kw;
- initData();
- }
- void setForumId(String? forumId) async {
- this._type = 100;
- this._forumId = forumId;
- initData();
- }
- void setForumIdAndOrigin(int type, String? forumId, String? isOfficial) {
- this._forumId = forumId?.isNotEmpty == true? forumId : null;
- this._isOfficial = isOfficial?.isNotEmpty == true? isOfficial : null;
- this._type = type;
- initData();
- }
- @override
- Future<List> loadData({int pageNum = 1}) async {
- List results = [];
- switch (_type) {
- case 100:
- results = handlePage(await api.getPostList(
- kw: _kw,
- page: max(1, pageNum),
- forumId: _forumId,
- isOfficial: _isOfficial));
- break;
- // 第四个变成公共了...
- case 4:
- results = handlePage(await api.getPostListByOfficial(
- page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
- break;
- // case 4:
- // SharedPreferences prefs = await SharedPreferences.getInstance();
- // results = handlePage(await api.getPostListByUser(
- // prefs.getInt("id").toString(),
- // forumId: _forumId,
- // page: max(1, pageNum)));
- // break;
- case 3:
- results = handlePage(await api.getPostList(
- isGood: 1,
- page: max(1, pageNum),
- forumId: _forumId,
- isOfficial: _isOfficial));
- break;
- case 2:
- results = handlePage(await api.getPostList(
- page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
- break;
- case 1:
- SharedPreferences prefs = await SharedPreferences.getInstance();
- results = handlePage(
- await api.getPostListByFollow(prefs.getInt("id").toString(),
- page: max(1, pageNum),
- forumId: _forumId,
- isOfficial: _isOfficial),
- );
- break;
- default:
- results = handlePage(await api.getPostListByHot(
- page: max(1, pageNum), forumId: _forumId, isOfficial: _isOfficial));
- break;
- }
- return results;
- }
- }
|