2022-12-25 00:55:53 +00:00
|
|
|
import '../dtos/image_model_dto.dart';
|
2022-12-23 23:32:53 +00:00
|
|
|
|
2022-12-25 21:17:59 +00:00
|
|
|
/// Represents an Image, that would be displayed in the gallery.
|
2022-12-20 20:52:24 +00:00
|
|
|
class ImageModel {
|
2023-01-01 12:04:22 +00:00
|
|
|
const ImageModel._({
|
2022-12-20 19:29:46 +00:00
|
|
|
required this.uri,
|
2022-12-20 20:52:24 +00:00
|
|
|
required this.imageIndex,
|
2022-12-20 19:29:46 +00:00
|
|
|
required this.imageName,
|
2022-12-25 00:55:53 +00:00
|
|
|
required this.isFavourite,
|
2022-12-20 19:29:46 +00:00
|
|
|
});
|
|
|
|
|
2023-01-01 12:04:22 +00:00
|
|
|
factory ImageModel.fromDto({
|
|
|
|
required ImageModelDTO imageModelDto,
|
|
|
|
required bool isFavourite,
|
|
|
|
}) =>
|
|
|
|
ImageModel._(
|
|
|
|
uri: imageModelDto.uri,
|
|
|
|
imageIndex: imageModelDto.imageIndex,
|
|
|
|
imageName: imageModelDto.imageName,
|
|
|
|
isFavourite: isFavourite,
|
|
|
|
);
|
|
|
|
|
2022-12-20 19:29:46 +00:00
|
|
|
/// An image's target [Uri].
|
|
|
|
///
|
|
|
|
/// Storing an image's [ByteData] is more expensive, memory-wise.
|
|
|
|
final Uri uri;
|
|
|
|
|
|
|
|
/// A unique identifier that can be used for indexing the image.
|
2022-12-20 20:52:24 +00:00
|
|
|
final int imageIndex;
|
2022-12-20 19:29:46 +00:00
|
|
|
|
|
|
|
/// Given name of the image.
|
|
|
|
final String imageName;
|
2022-12-23 23:32:53 +00:00
|
|
|
|
2022-12-25 00:55:53 +00:00
|
|
|
/// Whether the image was 'Starred' ot not.
|
|
|
|
final bool isFavourite;
|
|
|
|
|
|
|
|
ImageModel copyWith({
|
|
|
|
Uri? uri,
|
|
|
|
int? imageIndex,
|
|
|
|
String? imageName,
|
|
|
|
bool? isFavourite,
|
|
|
|
}) {
|
2023-01-01 12:04:22 +00:00
|
|
|
return ImageModel._(
|
2022-12-25 00:55:53 +00:00
|
|
|
uri: uri ?? this.uri,
|
|
|
|
imageIndex: imageIndex ?? this.imageIndex,
|
|
|
|
imageName: imageName ?? this.imageName,
|
|
|
|
isFavourite: isFavourite ?? this.isFavourite,
|
|
|
|
);
|
|
|
|
}
|
2022-12-20 19:29:46 +00:00
|
|
|
}
|