123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import 'dart:math';
- import 'package:sport/bean/forum.dart';
- import 'package:sport/bean/post.dart';
- import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
- import 'package:sport/provider/social_detail_model.dart';
- import 'package:sport/services/api/inject_api.dart';
- class UserDetailModel extends SocialDetailModel with InjectApi {
- int type = 0;
- String id;
- Forum forum;
- String _sortBy = "created_at";
- UserDetailModel(this.id) : super(0);
- @override
- Future<List> loadData({int pageNum = 1}) async {
- List items = [];
- if (pageNum == 1) {
- var top = await api.getPostUserTopSubjects(id);
- if (top?.results?.isNotEmpty == true) {
- top.results.forEach((element) {element.isUserTop = "1";});
- items.addAll(top.results);
- }
- }
- // 这里修改了下 论坛...
- var page = handlePage(await api.getPostListByUser(id, page: max(pageNum, 1), sortBy: _sortBy, removeTop: 1));
- if (page?.isNotEmpty == true) {
- items.addAll(page);
- }
- return items;
- }
- forumBy(Forum forum) {
- this.forum = forum;
- // forumId = forum?.forumId;
- initData();
- }
- sortBy(String name) {
- if (name == "时间倒序") {
- _sortBy = "created_at";
- } else if (name == "点赞最多") {
- _sortBy = "like_count";
- } else if (name == "评论最多") {
- _sortBy = "comment_count";
- }
- initData();
- }
- }
|