user_info.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:get/get.dart';
  2. import 'package:json_annotation/json_annotation.dart';
  3. import 'location_info.dart';
  4. part 'user_info.g.dart';
  5. @JsonSerializable()
  6. class UserInfo {
  7. @JsonKey(name: 'friendId')
  8. final String id;
  9. @JsonKey(name: 'phone')
  10. final String phoneNumber;
  11. @JsonKey(name: 'name')
  12. final String? name;
  13. @JsonKey(name: 'remark')
  14. String? remark;
  15. @JsonKey(name: 'timestamp')
  16. final int? timestamp;
  17. @JsonKey(name: 'blockedHim')
  18. bool? blockedHim;
  19. @JsonKey(name: 'blockedMe')
  20. final bool? blockedMe;
  21. @JsonKey(name: 'location', ignore: true)
  22. final Rxn<LocationInfo> lastLocation = Rxn<LocationInfo>();
  23. @JsonKey(name: 'virtual')
  24. final bool? virtual;
  25. @JsonKey(name: 'avatar')
  26. String? avatar;
  27. final bool? isMine;
  28. late bool? isShowYesterday;
  29. UserInfo({
  30. required this.id,
  31. required this.phoneNumber,
  32. this.name,
  33. this.remark,
  34. this.timestamp,
  35. this.blockedHim,
  36. this.blockedMe,
  37. this.virtual,
  38. this.isMine,
  39. this.avatar,
  40. this.isShowYesterday
  41. });
  42. factory UserInfo.fromJson(Map<String, dynamic> json) {
  43. final userinfo = _$UserInfoFromJson(json);
  44. LocationInfo? locationInfo = json['location'] == null
  45. ? null
  46. : LocationInfo.fromJson(json['location'] as Map<String, dynamic>);
  47. userinfo.lastLocation.value = locationInfo;
  48. return userinfo;
  49. }
  50. String getUserNickName() {
  51. return (remark?.isNotEmpty == true ? remark : phoneNumber) ?? '';
  52. }
  53. void updateLocation(LocationInfo location) {
  54. lastLocation.value = location;
  55. }
  56. }