123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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<UserFriend>
- with InjectApi {
- int type;
- String kw;
- // Map map;
- List<SuspensionBean> items = [];
- UserFriendModel(this.type);
- @override
- Future<List<UserFriend>> loadData({int pageNum}) async {
- List<UserFriend> 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<UserFriend> 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<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- 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<String, dynamic> json) : name = json['name'];
- Map<String, dynamic> toJson() => {
- 'name': name,
- // 'tagIndex': tagIndex,
- // 'namePinyin': namePinyin,
- // 'isShowSuspension': isShowSuspension
- };
- @override
- String getSuspensionTag() => tagIndex;
- @override
- String toString() => json.encode(this);
- }
|