user_info.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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: 'remark')
  12. String? remark;
  13. @JsonKey(name: 'timestamp')
  14. final int? timestamp;
  15. @JsonKey(name: 'blockedHim')
  16. bool? blockedHim;
  17. @JsonKey(name: 'blockedMe')
  18. final bool? blockedMe;
  19. @JsonKey(name: 'location', ignore: true)
  20. final Rxn<LocationInfo> lastLocation = Rxn<LocationInfo>();
  21. @JsonKey(name: 'virtual')
  22. final bool? virtual;
  23. final bool? isMine;
  24. UserInfo({
  25. required this.id,
  26. required this.phoneNumber,
  27. this.remark,
  28. this.timestamp,
  29. this.blockedHim,
  30. this.blockedMe,
  31. this.virtual,
  32. this.isMine,
  33. });
  34. factory UserInfo.fromJson(Map<String, dynamic> json) {
  35. final userinfo = _$UserInfoFromJson(json);
  36. LocationInfo? locationInfo = json['location'] == null
  37. ? null
  38. : LocationInfo.fromJson(json['location'] as Map<String, dynamic>);
  39. userinfo.lastLocation.value = locationInfo;
  40. return userinfo;
  41. }
  42. String getUserNickName() {
  43. return (remark?.isNotEmpty == true ? remark : phoneNumber) ?? '';
  44. }
  45. void updateLocation(LocationInfo location) {
  46. lastLocation.value = location;
  47. }
  48. }