From 9ae2ae820da8c8e371746eaaab4b936257627c20 Mon Sep 17 00:00:00 2001 From: gg12 darfren Date: Fri, 20 Dec 2024 21:17:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B4=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/dtos/character_dto.dart | 17 ++++++++++++++++- lib/data/mappers/character_mapper.dart | 14 +++++++++++++- lib/presentation/home_page/card.dart | 4 ++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/data/dtos/character_dto.dart b/lib/data/dtos/character_dto.dart index 68aec1a..20fa264 100644 --- a/lib/data/dtos/character_dto.dart +++ b/lib/data/dtos/character_dto.dart @@ -39,9 +39,24 @@ class CharacterDataDto { class CharacterDataAttributesDto { final String? birthdate; final String? sex; + final String? status; + @JsonKey(name: 'clan', fromJson: _mapClans) + final List? clans; - const CharacterDataAttributesDto({this.birthdate, this.sex}); + const CharacterDataAttributesDto({this.birthdate, this.sex, this.status, this.clans}); factory CharacterDataAttributesDto.fromJson(Map json) => _$CharacterDataAttributesDtoFromJson(json); + + static List? _mapClans(dynamic value) { + if(value == null) + return null; + try { + return (value as List?)?.map((e) => e as String).toList(); + } + catch(e){ + List res = [value]; + return res; + } + } } \ No newline at end of file diff --git a/lib/data/mappers/character_mapper.dart b/lib/data/mappers/character_mapper.dart index f9758c6..d934ea4 100644 --- a/lib/data/mappers/character_mapper.dart +++ b/lib/data/mappers/character_mapper.dart @@ -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; } } diff --git a/lib/presentation/home_page/card.dart b/lib/presentation/home_page/card.dart index c045848..26babee 100644 --- a/lib/presentation/home_page/card.dart +++ b/lib/presentation/home_page/card.dart @@ -105,6 +105,10 @@ class _Card extends StatelessWidget { name, style: Theme.of(context).textTheme.headlineLarge, ), + Text( + descriptionText, + style: Theme.of(context).textTheme.bodyLarge, + ), ], ), ),