user_info.dart 1.4 KB

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