code_display.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /// Used to store the display settings of a code.
  2. class CodeDisplay {
  3. final bool pinned;
  4. final bool trashed;
  5. final int lastUsedAt;
  6. final int tapCount;
  7. CodeDisplay({
  8. this.pinned = false,
  9. this.trashed = false,
  10. this.lastUsedAt = 0,
  11. this.tapCount = 0,
  12. });
  13. // copyWith
  14. CodeDisplay copyWith({
  15. bool? pinned,
  16. bool? trashed,
  17. int? lastUsedAt,
  18. int? tapCount,
  19. }) {
  20. final bool updatedPinned = pinned ?? this.pinned;
  21. final bool updatedTrashed = trashed ?? this.trashed;
  22. final int updatedLastUsedAt = lastUsedAt ?? this.lastUsedAt;
  23. final int updatedTapCount = tapCount ?? this.tapCount;
  24. return CodeDisplay(
  25. pinned: updatedPinned,
  26. trashed: updatedTrashed,
  27. lastUsedAt: updatedLastUsedAt,
  28. tapCount: updatedTapCount,
  29. );
  30. }
  31. factory CodeDisplay.fromJson(Map<String, dynamic>? json) {
  32. if (json == null) {
  33. return CodeDisplay();
  34. }
  35. return CodeDisplay(
  36. pinned: json['pinned'] ?? false,
  37. trashed: json['trashed'] ?? false,
  38. lastUsedAt: json['lastUsedAt'] ?? 0,
  39. tapCount: json['tapCount'] ?? 0,
  40. );
  41. }
  42. Map<String, dynamic> toJson() {
  43. return {
  44. 'pinned': pinned,
  45. 'trashed': trashed,
  46. 'lastUsedAt': lastUsedAt,
  47. 'tapCount': tapCount,
  48. };
  49. }
  50. }