import 'package:get/get.dart'; import 'package:json_annotation/json_annotation.dart'; import 'location_info.dart'; part 'user_info.g.dart'; @JsonSerializable() class UserInfo { @JsonKey(name: 'friendId') final String id; @JsonKey(name: 'phone') final String phoneNumber; @JsonKey(name: 'remark') String? remark; @JsonKey(name: 'timestamp') final int? timestamp; @JsonKey(name: 'blockedHim') bool? blockedHim; @JsonKey(name: 'blockedMe') final bool? blockedMe; @JsonKey(name: 'location', ignore: true) final Rxn lastLocation = Rxn(); @JsonKey(name: 'virtual') final bool? virtual; @JsonKey(name: 'avatar') String? avatar; final bool? isMine; UserInfo({ required this.id, required this.phoneNumber, this.remark, this.timestamp, this.blockedHim, this.blockedMe, this.virtual, this.isMine, this.avatar, }); factory UserInfo.fromJson(Map json) { final userinfo = _$UserInfoFromJson(json); LocationInfo? locationInfo = json['location'] == null ? null : LocationInfo.fromJson(json['location'] as Map); userinfo.lastLocation.value = locationInfo; return userinfo; } String getUserNickName() { return (remark?.isNotEmpty == true ? remark : phoneNumber) ?? ''; } void updateLocation(LocationInfo location) { lastLocation.value = location; } }