Favourites
This commit is contained in:
parent
6a84a9bef0
commit
1747ab0245
23 changed files with 469 additions and 67 deletions
26
lib/features/home/data/dtos/image_model_dto.dart
Normal file
26
lib/features/home/data/dtos/image_model_dto.dart
Normal file
|
@ -0,0 +1,26 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'image_model_dto.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ImageModelDTO {
|
||||
const ImageModelDTO({
|
||||
required this.uri,
|
||||
required this.imageIndex,
|
||||
required this.imageName,
|
||||
});
|
||||
|
||||
/// 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.
|
||||
final int imageIndex;
|
||||
|
||||
/// Given name of the image.
|
||||
final String imageName;
|
||||
|
||||
factory ImageModelDTO.fromJson(Map<String, dynamic> json) => _$ImageModelDTOFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ImageModelDTOToJson(this);
|
||||
}
|
|
@ -1,18 +1,19 @@
|
|||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'image_model.dart';
|
||||
part of 'image_model_dto.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ImageModel _$ImageModelFromJson(Map<String, dynamic> json) => ImageModel(
|
||||
ImageModelDTO _$ImageModelDTOFromJson(Map<String, dynamic> json) =>
|
||||
ImageModelDTO(
|
||||
uri: Uri.parse(json['uri'] as String),
|
||||
imageIndex: json['imageIndex'] as int,
|
||||
imageName: json['imageName'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ImageModelToJson(ImageModel instance) =>
|
||||
Map<String, dynamic> _$ImageModelDTOToJson(ImageModelDTO instance) =>
|
||||
<String, dynamic>{
|
||||
'uri': instance.uri.toString(),
|
||||
'imageIndex': instance.imageIndex,
|
|
@ -1,13 +1,11 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
import '../dtos/image_model_dto.dart';
|
||||
|
||||
part 'image_model.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class ImageModel {
|
||||
const ImageModel({
|
||||
required this.uri,
|
||||
required this.imageIndex,
|
||||
required this.imageName,
|
||||
required this.isFavourite,
|
||||
});
|
||||
|
||||
/// An image's target [Uri].
|
||||
|
@ -21,8 +19,31 @@ class ImageModel {
|
|||
/// Given name of the image.
|
||||
final String imageName;
|
||||
|
||||
factory ImageModel.fromJson(Map<String, dynamic> json) => _$ImageModelFromJson(json);
|
||||
/// Whether the image was 'Starred' ot not.
|
||||
final bool isFavourite;
|
||||
|
||||
/// Connect the generated [_$PersonToJson] function to the `toJson` method.
|
||||
Map<String, dynamic> toJson() => _$ImageModelToJson(this);
|
||||
factory ImageModel.fromDto({
|
||||
required ImageModelDTO imageModelDto,
|
||||
required bool isFavourite,
|
||||
}) =>
|
||||
ImageModel(
|
||||
uri: imageModelDto.uri,
|
||||
imageIndex: imageModelDto.imageIndex,
|
||||
imageName: imageModelDto.imageName,
|
||||
isFavourite: isFavourite,
|
||||
);
|
||||
|
||||
ImageModel copyWith({
|
||||
Uri? uri,
|
||||
int? imageIndex,
|
||||
String? imageName,
|
||||
bool? isFavourite,
|
||||
}) {
|
||||
return ImageModel(
|
||||
uri: uri ?? this.uri,
|
||||
imageIndex: imageIndex ?? this.imageIndex,
|
||||
imageName: imageName ?? this.imageName,
|
||||
isFavourite: isFavourite ?? this.isFavourite,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue