Process...

This commit is contained in:
Вячеслав Иванов 2024-09-22 22:30:44 +04:00
parent 7586e41f41
commit f80bc53118
7 changed files with 25 additions and 27 deletions

View File

@ -29,11 +29,11 @@ class CharacterDataDto {
@JsonSerializable(createToJson: false)
class CharacterAttributesDataDto {
final String? name;
final String? born;
final String? died;
final String? nationality;
final String? species;
final String? image;
const CharacterAttributesDataDto({this.name, this.born, this.died, this.image});
const CharacterAttributesDataDto({this.name, this.nationality, this.species, this.image});
factory CharacterAttributesDataDto.fromJson(Map<String, dynamic> json) =>
_$CharacterAttributesDataDtoFromJson(json);

View File

@ -30,8 +30,8 @@ CharacterAttributesDataDto _$CharacterAttributesDataDtoFromJson(
Map<String, dynamic> json) =>
CharacterAttributesDataDto(
name: json['name'] as String?,
born: json['born'] as String?,
died: json['died'] as String?,
nationality: json['nationality'] as String?,
species: json['species'] as String?,
image: json['image'] as String?,
);

View File

@ -2,9 +2,6 @@ import '../../domain/models/card.dart';
import '../../domain/models/home.dart';
import '../dtos/characters_dto.dart';
const _imagePlaceholder =
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png';
extension CharactersDtoToModel on CharactersDto {
HomeData toDomain() => HomeData(
data: data?.map((e) => e.toDomain()).toList(),
@ -15,18 +12,19 @@ extension CharactersDtoToModel on CharactersDto {
extension CharacterDataDtoToModel on CharacterDataDto {
CardData toDomain() => CardData(
attributes?.name ?? 'UNKNOWN',
imageUrl: attributes?.image ?? _imagePlaceholder,
descriptionText: _makeDescriptionText(attributes?.born, attributes?.died),
image: attributes?.image ??
'https://upload.wikimedia.org/wikipedia/en/archive/b/b1/20210811082420%21Portrait_placeholder.png',
descriptionText: _makeDescriptionText(attributes?.nationality, attributes?.species),
id: id,
);
String _makeDescriptionText(String? born, String? died) {
return born != null && died != null
? '$born - $died'
: born != null
? 'born: $born'
: died != null
? 'died: $died'
String _makeDescriptionText(String? nationality, String? species) {
return nationality != null && species != null
? 'Nationality - $nationality \nSpecies - $species'
: nationality != null
? 'Nationality - $nationality'
: species != null
? 'Species - $species'
: '';
}
}

View File

@ -11,21 +11,21 @@ class MockRepository extends ApiInterface {
CardData(
'Freeze',
descriptionText: 'so cold..',
imageUrl:
image:
'https://www.skedaddlewildlife.com/wp-content/uploads/2018/09/depositphotos_22425309-stock-photo-a-lonely-raccoon-in-winter.jpg',
),
CardData(
'Hi',
descriptionText: 'pretty face',
icon: Icons.hail,
imageUrl:
image:
'https://www.thesprucepets.com/thmb/nKNaS4I586B_H7sEUw9QAXvWM_0=/2121x0/filters:no_upscale():strip_icc()/GettyImages-135630198-5ba7d225c9e77c0050cff91b.jpg',
),
CardData(
'Orange',
descriptionText: 'I like autumn',
icon: Icons.warning_amber,
imageUrl: 'https://furmanagers.com/wp-content/uploads/2019/11/dreamstime_l_22075357.jpg',
image: 'https://furmanagers.com/wp-content/uploads/2019/11/dreamstime_l_22075357.jpg',
),
],
);

View File

@ -4,14 +4,14 @@ class CardData {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
final String? image;
final String? id;
CardData(
this.text, {
required this.descriptionText,
this.icon = Icons.ac_unit_outlined,
this.imageUrl,
this.image,
this.id,
});
}

View File

@ -16,7 +16,7 @@ class DetailsPage extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Image.network(
data.imageUrl ?? '',
data.image ?? '',
),
),
Padding(

View File

@ -6,7 +6,7 @@ class _Card extends StatelessWidget {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
final String? image;
final OnLikeCallback onLike;
final VoidCallback? onTap;
final String? id;
@ -16,7 +16,7 @@ class _Card extends StatelessWidget {
this.text, {
this.icon = Icons.ac_unit_outlined,
required this.descriptionText,
this.imageUrl,
this.image,
this.onLike,
this.onTap,
this.id,
@ -33,7 +33,7 @@ class _Card extends StatelessWidget {
data.text,
descriptionText: data.descriptionText,
icon: data.icon,
imageUrl: data.imageUrl,
image: data.image,
onLike: onLike,
onTap: onTap,
isLiked: isLiked,
@ -75,7 +75,7 @@ class _Card extends StatelessWidget {
children: [
Positioned.fill(
child: Image.network(
imageUrl ?? '',
image ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),