user_info.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. UserInfo({
  29. required this.id,
  30. required this.phoneNumber,
  31. this.name,
  32. this.remark,
  33. this.timestamp,
  34. this.blockedHim,
  35. this.blockedMe,
  36. this.virtual,
  37. this.isMine,
  38. this.avatar,
  39. });
  40. factory UserInfo.fromJson(Map<String, dynamic> json) {
  41. final userinfo = _$UserInfoFromJson(json);
  42. LocationInfo? locationInfo = json['location'] == null
  43. ? null
  44. : LocationInfo.fromJson(json['location'] as Map<String, dynamic>);
  45. userinfo.lastLocation.value = locationInfo;
  46. return userinfo;
  47. }
  48. String getUserNickName() {
  49. return (remark?.isNotEmpty == true ? remark : phoneNumber) ?? '';
  50. }
  51. void updateLocation(LocationInfo location) {
  52. lastLocation.value = location;
  53. }
  54. }