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 with InjectApi { int type; String? kw; List originList = []; List tags = []; Map tagsIndex = {}; Map tagsIndexs = {}; UserFriendModel(this.type); @override Future> loadData({int pageNum = 0}) async { List? 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 toJson() { final Map data = new Map(); data['tag'] = this.tag; data['user'] = this.user.toJson(); return data; } }