подправил дто
This commit is contained in:
parent
1d9d1bc043
commit
9ae2ae820d
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -105,6 +105,10 @@ class _Card extends StatelessWidget {
|
||||
name,
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
Text(
|
||||
descriptionText,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user