подправил дто

This commit is contained in:
gg12 darfren 2024-12-20 21:17:23 +04:00
parent 1d9d1bc043
commit 9ae2ae820d
3 changed files with 33 additions and 2 deletions

View File

@ -39,9 +39,24 @@ class CharacterDataDto {
class CharacterDataAttributesDto {
final String? birthdate;
final String? sex;
final String? status;
@JsonKey(name: 'clan', fromJson: _mapClans)
final List<String>? clans;
const CharacterDataAttributesDto({this.birthdate, this.sex});
const CharacterDataAttributesDto({this.birthdate, this.sex, this.status, this.clans});
factory CharacterDataAttributesDto.fromJson(Map<String, dynamic> json) =>
_$CharacterDataAttributesDtoFromJson(json);
static List<String>? _mapClans(dynamic value) {
if(value == null)
return null;
try {
return (value as List<dynamic>?)?.map((e) => e as String).toList();
}
catch(e){
List<String> res = [value];
return res;
}
}
}

View File

@ -23,6 +23,18 @@ extension CharacterDataDtoToModel on CharacterDataDto {
String _makeDescriptionText() {
return 'birthdate: ${attributes != null ? (attributes?.birthdate ?? 'unknown') : 'unknown'}\n'
'sex: ${attributes != null ? (attributes?.sex ?? 'unknown') : 'unknown'}\n';
'sex: ${attributes != null ? (attributes?.sex ?? 'unknown') : 'unknown'}\n'
'${attributes != null ? (_makeClans() ?? 'unknown') : 'unknown'}\n'
'status: ${attributes != null ? (attributes?.status ?? 'unknown') : 'unknown'}';
}
String _makeClans(){
if(attributes?.clans == null)
return 'clans: unknown';
String res = 'clans: ' + attributes!.clans![0];
for (int i = 1; i < attributes!.clans!.length; i++){
res += ', ' + attributes!.clans![i];
}
return res;
}
}

View File

@ -105,6 +105,10 @@ class _Card extends StatelessWidget {
name,
style: Theme.of(context).textTheme.headlineLarge,
),
Text(
descriptionText,
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),