user_friend_model.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'dart:convert';
  2. import 'dart:math';
  3. import 'package:azlistview/azlistview.dart';
  4. import 'package:sport/bean/user_friend.dart';
  5. import 'package:sport/bean/friend_list.dart';
  6. import 'package:sport/provider/lib/view_state_refresh_list_model.dart';
  7. import 'package:sport/services/api/inject_api.dart';
  8. class UserFriendModel extends ViewStateRefreshListModel<UserFriend> with InjectApi {
  9. int type;
  10. String? kw;
  11. List<UserFriend> originList = [];
  12. List<String> tags = [];
  13. Map<String, int> tagsIndex = {};
  14. Map<int, String> tagsIndexs = {};
  15. UserFriendModel(this.type);
  16. @override
  17. Future<List<UserFriend>> loadData({int pageNum = 0}) async {
  18. List<UserFriend>? results = [];
  19. switch (type) {
  20. case 2:
  21. results = (await api.userFansList(kw: kw, page: max(1, pageNum))).data?.list;
  22. break;
  23. case 1:
  24. results = (await api.userFollowList(kw: kw, page: max(1, pageNum))).data?.list;
  25. break;
  26. default:
  27. FriendList? data = (await api.userFriendsTest(kw: kw, page: max(1, pageNum), test: "1")).data;
  28. tags = data?.map?.keys.toList() ?? [];
  29. tagsIndex = {};
  30. tagsIndexs = {};
  31. data?.map?.forEach((key, value) {
  32. tagsIndexs[results!.length] = key;
  33. tagsIndex[key] = results.length;
  34. value.forEach((element) {
  35. results!.add(UserFriend.fromJson(element));
  36. });
  37. });
  38. break;
  39. }
  40. originList = results ?? [];
  41. return results ?? [];
  42. }
  43. void submitValue(String? value) {
  44. this.kw = value;
  45. refresh(init: true);
  46. }
  47. }
  48. class SuspensionBean extends ISuspensionBean {
  49. final String tag;
  50. final UserFriend user;
  51. SuspensionBean(this.tag, this.user);
  52. @override
  53. String getSuspensionTag() => tag;
  54. Map<String, dynamic> toJson() {
  55. final Map<String, dynamic> data = new Map<String, dynamic>();
  56. data['tag'] = this.tag;
  57. data['user'] = this.user.toJson();
  58. return data;
  59. }
  60. }