2020-08-14 18:07:27 +08:00
|
|
|
part of photogallery;
|
|
|
|
|
|
|
|
/// A medium in the gallery.
|
|
|
|
///
|
|
|
|
/// It can be of image or video [mediumType].
|
|
|
|
@immutable
|
|
|
|
class Medium {
|
|
|
|
/// A unique identifier for the medium.
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
/// The medium type.
|
2021-03-18 12:00:31 +00:00
|
|
|
final MediumType? mediumType;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
/// The medium width.
|
2021-03-18 12:00:31 +00:00
|
|
|
final int? width;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
/// The medium height.
|
2021-03-18 12:00:31 +00:00
|
|
|
final int? height;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
2021-07-09 18:45:20 +02:00
|
|
|
/// The medium orientation.
|
|
|
|
final int? orientation;
|
|
|
|
|
2021-01-10 21:43:18 +08:00
|
|
|
/// The medium mimeType.
|
2021-03-18 12:00:31 +00:00
|
|
|
final String? mimeType;
|
2021-01-10 21:43:18 +08:00
|
|
|
|
2020-08-18 16:12:06 +08:00
|
|
|
/// The duration of video
|
|
|
|
final int duration;
|
|
|
|
|
2020-08-14 18:07:27 +08:00
|
|
|
/// The date at which the photo or video was taken.
|
2021-03-18 12:00:31 +00:00
|
|
|
final DateTime? creationDate;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
/// The date at which the photo or video was modified.
|
2021-03-18 12:00:31 +00:00
|
|
|
final DateTime? modifiedDate;
|
2020-08-14 18:07:27 +08:00
|
|
|
|
|
|
|
Medium({
|
2021-03-18 12:00:31 +00:00
|
|
|
required this.id,
|
2020-08-14 18:07:27 +08:00
|
|
|
this.mediumType,
|
|
|
|
this.width,
|
|
|
|
this.height,
|
2021-07-09 18:45:20 +02:00
|
|
|
this.orientation = 0,
|
2021-01-10 21:43:18 +08:00
|
|
|
this.mimeType,
|
2021-03-18 12:00:31 +00:00
|
|
|
this.duration = 0,
|
2020-08-14 18:07:27 +08:00
|
|
|
this.creationDate,
|
|
|
|
this.modifiedDate,
|
|
|
|
});
|
|
|
|
|
|
|
|
/// Creates a medium from platform channel protocol.
|
|
|
|
Medium.fromJson(dynamic json)
|
|
|
|
: id = json["id"],
|
|
|
|
mediumType = jsonToMediumType(json["mediumType"]),
|
|
|
|
width = json["width"],
|
|
|
|
height = json["height"],
|
2021-07-09 18:45:20 +02:00
|
|
|
orientation = json["orientation"],
|
2021-01-10 21:43:18 +08:00
|
|
|
mimeType = json["mimeType"],
|
2020-08-18 16:12:06 +08:00
|
|
|
duration = json['duration'] ?? 0,
|
2020-08-14 18:07:27 +08:00
|
|
|
creationDate = json['creationDate'] != null
|
|
|
|
? DateTime.fromMillisecondsSinceEpoch(json['creationDate'])
|
|
|
|
: null,
|
|
|
|
modifiedDate = json['modifiedDate'] != null
|
|
|
|
? DateTime.fromMillisecondsSinceEpoch(json['modifiedDate'])
|
|
|
|
: null;
|
|
|
|
|
|
|
|
static Medium fromMap(Map map) {
|
|
|
|
return Medium(
|
|
|
|
id: map['id'],
|
|
|
|
mediumType: jsonToMediumType(map['mediumType']),
|
|
|
|
width: map['width'],
|
|
|
|
height: map['height'],
|
2021-07-09 18:45:20 +02:00
|
|
|
orientation: map['orientation'],
|
2021-01-10 21:43:18 +08:00
|
|
|
mimeType: map["mimeType"],
|
2020-08-14 18:07:27 +08:00
|
|
|
creationDate: map['creationDate'],
|
|
|
|
modifiedDate: map['modifiedDate'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map toMap() {
|
|
|
|
return {
|
|
|
|
"id": this.id,
|
|
|
|
"mediumType": mediumTypeToJson(this.mediumType),
|
|
|
|
"height": this.height,
|
2021-07-09 18:45:20 +02:00
|
|
|
"orientation": this.orientation,
|
2021-01-10 21:43:18 +08:00
|
|
|
"mimeType": this.mimeType,
|
2020-08-14 18:07:27 +08:00
|
|
|
"width": this.width,
|
|
|
|
"creationDate": this.creationDate,
|
|
|
|
"modifiedDate": this.modifiedDate,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get a JPEG thumbnail's data for this medium.
|
|
|
|
Future<List<int>> getThumbnail({
|
2021-03-18 12:00:31 +00:00
|
|
|
int? width,
|
|
|
|
int? height,
|
|
|
|
bool? highQuality = false,
|
2020-08-14 18:07:27 +08:00
|
|
|
}) {
|
|
|
|
return PhotoGallery.getThumbnail(
|
|
|
|
mediumId: id,
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
mediumType: mediumType,
|
|
|
|
highQuality: highQuality,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the original file.
|
|
|
|
Future<File> getFile() {
|
|
|
|
return PhotoGallery.getFile(
|
|
|
|
mediumId: id,
|
|
|
|
mediumType: mediumType,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) =>
|
|
|
|
identical(this, other) ||
|
|
|
|
other is Medium &&
|
|
|
|
runtimeType == other.runtimeType &&
|
|
|
|
id == other.id &&
|
|
|
|
mediumType == other.mediumType &&
|
|
|
|
width == other.width &&
|
|
|
|
height == other.height &&
|
2021-07-09 18:45:20 +02:00
|
|
|
orientation == other.orientation &&
|
2021-01-10 21:43:18 +08:00
|
|
|
mimeType == other.mimeType &&
|
2020-08-14 18:07:27 +08:00
|
|
|
creationDate == other.creationDate &&
|
|
|
|
modifiedDate == other.modifiedDate;
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode =>
|
|
|
|
id.hashCode ^
|
|
|
|
mediumType.hashCode ^
|
|
|
|
width.hashCode ^
|
|
|
|
height.hashCode ^
|
2021-07-09 18:45:20 +02:00
|
|
|
orientation.hashCode ^
|
2021-01-10 21:43:18 +08:00
|
|
|
mimeType.hashCode ^
|
2020-08-14 18:07:27 +08:00
|
|
|
creationDate.hashCode ^
|
|
|
|
modifiedDate.hashCode;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return 'Medium{id: $id, '
|
|
|
|
'mediumType: $mediumType, '
|
|
|
|
'width: $width, '
|
|
|
|
'height: $height, '
|
2021-07-09 18:45:20 +02:00
|
|
|
'orientation: $orientation, '
|
2021-01-10 21:43:18 +08:00
|
|
|
'mimeType: $mimeType, '
|
2020-08-14 18:07:27 +08:00
|
|
|
'creationDate: $creationDate, '
|
|
|
|
'modifiedDate: $modifiedDate}';
|
|
|
|
}
|
|
|
|
}
|