collection_file_item.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import 'dart:convert';
  2. class CollectionFileItem {
  3. final int id;
  4. final String encryptedKey;
  5. final String keyDecryptionNonce;
  6. CollectionFileItem(
  7. this.id,
  8. this.encryptedKey,
  9. this.keyDecryptionNonce,
  10. );
  11. CollectionFileItem copyWith({
  12. int? id,
  13. String? encryptedKey,
  14. String? keyDecryptionNonce,
  15. }) {
  16. return CollectionFileItem(
  17. id ?? this.id,
  18. encryptedKey ?? this.encryptedKey,
  19. keyDecryptionNonce ?? this.keyDecryptionNonce,
  20. );
  21. }
  22. Map<String, dynamic> toMap() {
  23. return {
  24. 'id': id,
  25. 'encryptedKey': encryptedKey,
  26. 'keyDecryptionNonce': keyDecryptionNonce,
  27. };
  28. }
  29. static fromMap(Map<String, dynamic>? map) {
  30. if (map == null) return null;
  31. return CollectionFileItem(
  32. map['id'],
  33. map['encryptedKey'],
  34. map['keyDecryptionNonce'],
  35. );
  36. }
  37. String toJson() => json.encode(toMap());
  38. factory CollectionFileItem.fromJson(String source) =>
  39. CollectionFileItem.fromMap(json.decode(source));
  40. @override
  41. String toString() =>
  42. 'CollectionFileItem(id: $id, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce)';
  43. @override
  44. bool operator ==(Object o) {
  45. if (identical(this, o)) return true;
  46. return o is CollectionFileItem &&
  47. o.id == id &&
  48. o.encryptedKey == encryptedKey &&
  49. o.keyDecryptionNonce == keyDecryptionNonce;
  50. }
  51. @override
  52. int get hashCode =>
  53. id.hashCode ^ encryptedKey.hashCode ^ keyDecryptionNonce.hashCode;
  54. }