import 'dart:convert'; import 'dart:math'; import 'package:azlistview/azlistview.dart'; import 'package:sport/bean/user_friend.dart'; import 'package:sport/provider/lib/view_state_refresh_list_model.dart'; import 'package:sport/services/api/inject_api.dart'; import 'package:sport/services/api/resp.dart'; class UserFriendModel extends ViewStateRefreshListModel with InjectApi { int type; String kw; // Map map; List items = []; List originItems = []; List originList = []; List tags = []; UserFriendModel(this.type); @override Future> loadData({int pageNum}) async { List results = []; switch (type) { case 2: results = (await api.userFansList(kw: kw, page: max(1, pageNum))).results.list; originList = results; break; case 1: results = (await api.userFollowList(kw: kw, page: max(1, pageNum))).results.list; originList = results; break; default: ResultsTest data = (await api.userFriendsTest( kw: kw, page: max(1, pageNum), test: "1")) .results; items = []; tags = data.map.keys.toList(); data.map.forEach((key, value) { value.forEach((element) { items.add(SuspensionBean(key, UserFriend.fromJson(element))); }); }); // items.forEach((element) { // print(element.toJson()); // }); originItems = items; SuspensionUtil.setShowSuspensionStatus(items); SuspensionUtil.sortListBySuspensionTag(items); break; } print("[RESULTS]${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; } } class UserFriendListModel extends ISuspensionBean { String name; String tagIndex; String namePinyin; UserFriendListModel({ this.name, this.tagIndex, this.namePinyin, }); UserFriendListModel.fromJson(Map json) : name = json['name']; Map toJson() => { 'name': name, // 'tagIndex': tagIndex, // 'namePinyin': namePinyin, // 'isShowSuspension': isShowSuspension }; @override String getSuspensionTag() => tagIndex; @override String toString() => json.encode(this); }