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 = []; 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; break; case 1: results = (await api.userFollowList(kw: kw, page: max(1, pageNum))).results; break; default: ResultsTest data = (await api.userFriendsTest( kw: kw, page: max(1, pageNum), test: "1")) .results; // map = data.map; // items = data.map.keys.map((e) => SuspensionBean(e.toString(), data.map[e] as List)).toList(); items = []; data.map.forEach((key, value) { value.forEach((element) { items.add(SuspensionBean(key, UserFriend.fromJson(element))); }); }); items.forEach((element) { print(element.toJson()); }); SuspensionUtil.setShowSuspensionStatus(items); SuspensionUtil.sortListBySuspensionTag(items); // print("$items----------------${items.length}"); break; } 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); }