1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import 'dart:convert';
- import 'dart:math';
- import 'package:azlistview/azlistview.dart';
- import 'package:sport/bean/user_friend.dart';
- import 'package:sport/bean/friend_list.dart';
- import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
- import 'package:sport/services/api/inject_api.dart';
- class UserFriendModel extends ViewStateRefreshListModel<UserFriend> with InjectApi {
- int type;
- String? kw;
- List<UserFriend> originList = [];
- List<String> tags = [];
- Map<String, int> tagsIndex = {};
- Map<int, String> tagsIndexs = {};
- UserFriendModel(this.type);
- @override
- Future<List<UserFriend>> loadData({int pageNum = 0}) async {
- List<UserFriend>? results = [];
- switch (type) {
- case 2:
- results = (await api.userFansList(kw: kw, page: max(1, pageNum))).data?.list;
- break;
- case 1:
- results = (await api.userFollowList(kw: kw, page: max(1, pageNum))).data?.list;
- break;
- default:
- FriendList? data = (await api.userFriendsTest(kw: kw, page: max(1, pageNum), test: "1")).data;
- tags = data?.map?.keys.toList() ?? [];
- tagsIndex = {};
- tagsIndexs = {};
- data?.map?.forEach((key, value) {
- tagsIndexs[results!.length] = key;
- tagsIndex[key] = results.length;
- value.forEach((element) {
- results!.add(UserFriend.fromJson(element));
- });
- });
- break;
- }
- originList = results ?? [];
- return results ?? [];
- }
- void submitValue(String? value) {
- this.kw = value;
- refresh(init: true);
- }
- }
- class SuspensionBean extends ISuspensionBean {
- final String tag;
- final UserFriend user;
- SuspensionBean(this.tag, this.user);
- @override
- String getSuspensionTag() => tag;
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['tag'] = this.tag;
- data['user'] = this.user.toJson();
- return data;
- }
- }
|