exif_info.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import 'package:isar/isar.dart';
  2. import 'package:openapi/api.dart';
  3. part 'exif_info.g.dart';
  4. /// Exif information 1:1 relation with Asset
  5. @Collection(inheritance: false)
  6. class ExifInfo {
  7. Id? id;
  8. int? fileSize;
  9. String? make;
  10. String? model;
  11. String? lens;
  12. float? f;
  13. float? mm;
  14. short? iso;
  15. float? exposureSeconds;
  16. float? lat;
  17. float? long;
  18. String? city;
  19. String? state;
  20. String? country;
  21. String? description;
  22. @ignore
  23. String get exposureTime {
  24. if (exposureSeconds == null) {
  25. return "";
  26. } else if (exposureSeconds! < 1) {
  27. return "1/${(1.0 / exposureSeconds!).round()} s";
  28. } else {
  29. return "${exposureSeconds!.toStringAsFixed(1)} s";
  30. }
  31. }
  32. @ignore
  33. String get fNumber => f != null ? f!.toStringAsFixed(1) : "";
  34. @ignore
  35. String get focalLength => mm != null ? mm!.toStringAsFixed(1) : "";
  36. @ignore
  37. double? get latitude => lat;
  38. @ignore
  39. double? get longitude => long;
  40. ExifInfo.fromDto(ExifResponseDto dto)
  41. : fileSize = dto.fileSizeInByte,
  42. make = dto.make,
  43. model = dto.model,
  44. lens = dto.lensModel,
  45. f = dto.fNumber?.toDouble(),
  46. mm = dto.focalLength?.toDouble(),
  47. iso = dto.iso?.toInt(),
  48. exposureSeconds = _exposureTimeToSeconds(dto.exposureTime),
  49. lat = dto.latitude?.toDouble(),
  50. long = dto.longitude?.toDouble(),
  51. city = dto.city,
  52. state = dto.state,
  53. country = dto.country,
  54. description = dto.description;
  55. ExifInfo({
  56. this.id,
  57. this.fileSize,
  58. this.make,
  59. this.model,
  60. this.lens,
  61. this.f,
  62. this.mm,
  63. this.iso,
  64. this.exposureSeconds,
  65. this.lat,
  66. this.long,
  67. this.city,
  68. this.state,
  69. this.country,
  70. this.description,
  71. });
  72. ExifInfo copyWith({
  73. Id? id,
  74. int? fileSize,
  75. String? make,
  76. String? model,
  77. String? lens,
  78. float? f,
  79. float? mm,
  80. short? iso,
  81. float? exposureSeconds,
  82. float? lat,
  83. float? long,
  84. String? city,
  85. String? state,
  86. String? country,
  87. String? description,
  88. }) =>
  89. ExifInfo(
  90. id: id ?? this.id,
  91. fileSize: fileSize ?? this.fileSize,
  92. make: make ?? this.make,
  93. model: model ?? this.model,
  94. lens: lens ?? this.lens,
  95. f: f ?? this.f,
  96. mm: mm ?? this.mm,
  97. iso: iso ?? this.iso,
  98. exposureSeconds: exposureSeconds ?? this.exposureSeconds,
  99. lat: lat ?? this.lat,
  100. long: long ?? this.long,
  101. city: city ?? this.city,
  102. state: state ?? this.state,
  103. country: country ?? this.country,
  104. description: description ?? this.description,
  105. );
  106. @override
  107. bool operator ==(other) {
  108. if (other is! ExifInfo) return false;
  109. return id == other.id &&
  110. fileSize == other.fileSize &&
  111. make == other.make &&
  112. model == other.model &&
  113. lens == other.lens &&
  114. f == other.f &&
  115. mm == other.mm &&
  116. iso == other.iso &&
  117. exposureSeconds == other.exposureSeconds &&
  118. lat == other.lat &&
  119. long == other.long &&
  120. city == other.city &&
  121. state == other.state &&
  122. country == other.country &&
  123. description == other.description;
  124. }
  125. @override
  126. @ignore
  127. int get hashCode =>
  128. id.hashCode ^
  129. fileSize.hashCode ^
  130. make.hashCode ^
  131. model.hashCode ^
  132. lens.hashCode ^
  133. f.hashCode ^
  134. mm.hashCode ^
  135. iso.hashCode ^
  136. exposureSeconds.hashCode ^
  137. lat.hashCode ^
  138. long.hashCode ^
  139. city.hashCode ^
  140. state.hashCode ^
  141. country.hashCode ^
  142. description.hashCode;
  143. }
  144. double? _exposureTimeToSeconds(String? s) {
  145. if (s == null) {
  146. return null;
  147. }
  148. double? value = double.tryParse(s);
  149. if (value != null) {
  150. return value;
  151. }
  152. final parts = s.split("/");
  153. if (parts.length == 2) {
  154. final numerator = double.tryParse(parts[0]);
  155. final denominator = double.tryParse(parts[1]);
  156. if (numerator != null && denominator != null) {
  157. return numerator / denominator;
  158. }
  159. }
  160. return null;
  161. }