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); 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; this._isOfficial = isOfficial; this._type = type; initData(); } @override Future 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; } }