device_info.model.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'dart:convert';
  2. class DeviceInfoRemote {
  3. final int id;
  4. final String userId;
  5. final String deviceId;
  6. final String deviceType;
  7. final String notificationToken;
  8. final String createdAt;
  9. final bool isAutoBackup;
  10. DeviceInfoRemote({
  11. required this.id,
  12. required this.userId,
  13. required this.deviceId,
  14. required this.deviceType,
  15. required this.notificationToken,
  16. required this.createdAt,
  17. required this.isAutoBackup,
  18. });
  19. DeviceInfoRemote copyWith({
  20. int? id,
  21. String? userId,
  22. String? deviceId,
  23. String? deviceType,
  24. String? notificationToken,
  25. String? createdAt,
  26. bool? isAutoBackup,
  27. }) {
  28. return DeviceInfoRemote(
  29. id: id ?? this.id,
  30. userId: userId ?? this.userId,
  31. deviceId: deviceId ?? this.deviceId,
  32. deviceType: deviceType ?? this.deviceType,
  33. notificationToken: notificationToken ?? this.notificationToken,
  34. createdAt: createdAt ?? this.createdAt,
  35. isAutoBackup: isAutoBackup ?? this.isAutoBackup,
  36. );
  37. }
  38. Map<String, dynamic> toMap() {
  39. return {
  40. 'id': id,
  41. 'userId': userId,
  42. 'deviceId': deviceId,
  43. 'deviceType': deviceType,
  44. 'notificationToken': notificationToken,
  45. 'createdAt': createdAt,
  46. 'isAutoBackup': isAutoBackup,
  47. };
  48. }
  49. factory DeviceInfoRemote.fromMap(Map<String, dynamic> map) {
  50. return DeviceInfoRemote(
  51. id: map['id']?.toInt() ?? 0,
  52. userId: map['userId'] ?? '',
  53. deviceId: map['deviceId'] ?? '',
  54. deviceType: map['deviceType'] ?? '',
  55. notificationToken: map['notificationToken'] ?? '',
  56. createdAt: map['createdAt'] ?? '',
  57. isAutoBackup: map['isAutoBackup'] ?? false,
  58. );
  59. }
  60. String toJson() => json.encode(toMap());
  61. factory DeviceInfoRemote.fromJson(String source) =>
  62. DeviceInfoRemote.fromMap(json.decode(source));
  63. @override
  64. String toString() {
  65. return 'DeviceInfo(id: $id, userId: $userId, deviceId: $deviceId, deviceType: $deviceType, notificationToken: $notificationToken, createdAt: $createdAt, isAutoBackup: $isAutoBackup)';
  66. }
  67. @override
  68. bool operator ==(Object other) {
  69. if (identical(this, other)) return true;
  70. return other is DeviceInfoRemote &&
  71. other.id == id &&
  72. other.userId == userId &&
  73. other.deviceId == deviceId &&
  74. other.deviceType == deviceType &&
  75. other.notificationToken == notificationToken &&
  76. other.createdAt == createdAt &&
  77. other.isAutoBackup == isAutoBackup;
  78. }
  79. @override
  80. int get hashCode {
  81. return id.hashCode ^
  82. userId.hashCode ^
  83. deviceId.hashCode ^
  84. deviceType.hashCode ^
  85. notificationToken.hashCode ^
  86. createdAt.hashCode ^
  87. isAutoBackup.hashCode;
  88. }
  89. }