24 lines
697 B
Dart
24 lines
697 B
Dart
|
import 'package:pmd_lab/data/dtos/characters_dto.dart';
|
||
|
import 'package:pmd_lab/domain/models/card.dart';
|
||
|
|
||
|
|
||
|
const _imagePlaceholder = 'https://cdn-icons-png.flaticon.com/512/4054/4054617.png';
|
||
|
|
||
|
|
||
|
extension CharacterDataDtoToModel on CharactersDataDto {
|
||
|
CardData toDomain() => CardData(
|
||
|
attributes?.name ?? 'UNKNOWN',
|
||
|
imgUrl: attributes?.image ?? _imagePlaceholder,
|
||
|
description: _makeDescription(attributes?.born, attributes?.died),
|
||
|
);
|
||
|
|
||
|
String _makeDescription(String? born, String? died){
|
||
|
return born != null && died != null
|
||
|
? '$born - $died'
|
||
|
: born != null
|
||
|
? 'born: $born'
|
||
|
: died != null
|
||
|
? 'died: $died'
|
||
|
: '';
|
||
|
}
|
||
|
}
|