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) @JsonSerializable(createToJson: false)
class CharacterAttributesDataDto { class CharacterAttributesDataDto {
final String? name; final String? name;
final String? born; final String? nationality;
final String? died; final String? species;
final String? image; 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) => factory CharacterAttributesDataDto.fromJson(Map<String, dynamic> json) =>
_$CharacterAttributesDataDtoFromJson(json); _$CharacterAttributesDataDtoFromJson(json);

View File

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

View File

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

View File

@ -11,21 +11,21 @@ class MockRepository extends ApiInterface {
CardData( CardData(
'Freeze', 'Freeze',
descriptionText: 'so cold..', descriptionText: 'so cold..',
imageUrl: image:
'https://www.skedaddlewildlife.com/wp-content/uploads/2018/09/depositphotos_22425309-stock-photo-a-lonely-raccoon-in-winter.jpg', 'https://www.skedaddlewildlife.com/wp-content/uploads/2018/09/depositphotos_22425309-stock-photo-a-lonely-raccoon-in-winter.jpg',
), ),
CardData( CardData(
'Hi', 'Hi',
descriptionText: 'pretty face', descriptionText: 'pretty face',
icon: Icons.hail, icon: Icons.hail,
imageUrl: image:
'https://www.thesprucepets.com/thmb/nKNaS4I586B_H7sEUw9QAXvWM_0=/2121x0/filters:no_upscale():strip_icc()/GettyImages-135630198-5ba7d225c9e77c0050cff91b.jpg', 'https://www.thesprucepets.com/thmb/nKNaS4I586B_H7sEUw9QAXvWM_0=/2121x0/filters:no_upscale():strip_icc()/GettyImages-135630198-5ba7d225c9e77c0050cff91b.jpg',
), ),
CardData( CardData(
'Orange', 'Orange',
descriptionText: 'I like autumn', descriptionText: 'I like autumn',
icon: Icons.warning_amber, 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 text;
final String descriptionText; final String descriptionText;
final IconData icon; final IconData icon;
final String? imageUrl; final String? image;
final String? id; final String? id;
CardData( CardData(
this.text, { this.text, {
required this.descriptionText, required this.descriptionText,
this.icon = Icons.ac_unit_outlined, this.icon = Icons.ac_unit_outlined,
this.imageUrl, this.image,
this.id, this.id,
}); });
} }

View File

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

View File

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