From e7e2628e8b6a9712e90bf18594e50dfc74868de7 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Wed, 25 Sep 2024 19:28:26 +0400 Subject: [PATCH] =?UTF-8?q?lab5=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=20?= =?UTF-8?q?=D0=B1=D0=B5=D0=B7=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B0,=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=BC=D0=B5=D0=BD=D1=8F=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B0=D0=BF=D0=B8=D1=88=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/dtos/news_dto.dart | 13 ++----------- lib/data/dtos/news_dto.g.dart | 12 ++---------- lib/data/mappers/news_mapper.dart | 8 ++++---- lib/data/repositories/bbc_repository.dart | 2 +- lib/presentation/details_page/details_page.dart | 15 +++++++++------ 5 files changed, 18 insertions(+), 32 deletions(-) diff --git a/lib/data/dtos/news_dto.dart b/lib/data/dtos/news_dto.dart index 79f885c..5115185 100644 --- a/lib/data/dtos/news_dto.dart +++ b/lib/data/dtos/news_dto.dart @@ -2,20 +2,12 @@ import 'package:json_annotation/json_annotation.dart'; part 'news_dto.g.dart'; @JsonSerializable(createToJson: false) class NewsDto{ - final List? data; + @JsonKey(name: 'Главное') + final List? data; const NewsDto({this.data}); factory NewsDto.fromJson(Map json) => _$NewsDtoFromJson(json); } -@JsonSerializable(createToJson: false) -class NewDataDto{ - final String? id; - final String? type; - final NewAttributesDataDto? attributes; - const NewDataDto({this.id, this.type, this.attributes}); - - factory NewDataDto.fromJson(Map json) => _$NewDataDtoFromJson(json); -} @JsonSerializable(createToJson: false) class NewAttributesDataDto{ @@ -26,5 +18,4 @@ class NewAttributesDataDto{ const NewAttributesDataDto({this.title, this.summary, this.imagelink }); factory NewAttributesDataDto.fromJson(Map json) => _$NewAttributesDataDtoFromJson(json); - } \ No newline at end of file diff --git a/lib/data/dtos/news_dto.g.dart b/lib/data/dtos/news_dto.g.dart index 96aa89a..adca9de 100644 --- a/lib/data/dtos/news_dto.g.dart +++ b/lib/data/dtos/news_dto.g.dart @@ -7,19 +7,11 @@ part of 'news_dto.dart'; // ************************************************************************** NewsDto _$NewsDtoFromJson(Map json) => NewsDto( - data: (json['data'] as List?) - ?.map((e) => NewDataDto.fromJson(e as Map)) + data: (json['Главное'] as List?) + ?.map((e) => NewAttributesDataDto.fromJson(e as Map)) .toList(), ); -NewDataDto _$NewDataDtoFromJson(Map json) => NewDataDto( - id: json['id'] as String?, - type: json['type'] as String?, - attributes: json['attributes'] == null - ? null - : NewAttributesDataDto.fromJson( - json['attributes'] as Map), - ); NewAttributesDataDto _$NewAttributesDataDtoFromJson( Map json) => diff --git a/lib/data/mappers/news_mapper.dart b/lib/data/mappers/news_mapper.dart index d2e2e9c..af04f92 100644 --- a/lib/data/mappers/news_mapper.dart +++ b/lib/data/mappers/news_mapper.dart @@ -1,10 +1,10 @@ import 'package:pmu/data/dtos/news_dto.dart'; import 'package:pmu/domain/models/card.dart'; -extension NewDataDtoToModel on NewDataDto{ +extension NewDataDtoToModel on NewAttributesDataDto{ CardData toDomain() => CardData( - text: attributes?.title ?? 'UNKNOWN', - imageUrl: attributes?.imagelink, - descText: attributes?.summary ?? 'NOTHING', + text: title ?? 'UNKNOWN', + imageUrl: imagelink, + descText: summary ?? 'NOTHING', ); } \ No newline at end of file diff --git a/lib/data/repositories/bbc_repository.dart b/lib/data/repositories/bbc_repository.dart index 5fb8b35..40eb888 100644 --- a/lib/data/repositories/bbc_repository.dart +++ b/lib/data/repositories/bbc_repository.dart @@ -20,7 +20,7 @@ class BbcRepository extends ApiInterface { const String url = '$_baseUrl/news?lang=russian'; final Response response = await _dio.get>( url, - // queryParameters: q != null ? {'filter[name_cont]': q} : null, + //queryParameters: q != null ? {'filter[name_cont]': q} : null, ); final NewsDto dto = NewsDto.fromJson(response.data as Map); diff --git a/lib/presentation/details_page/details_page.dart b/lib/presentation/details_page/details_page.dart index 1669ea2..539b18f 100644 --- a/lib/presentation/details_page/details_page.dart +++ b/lib/presentation/details_page/details_page.dart @@ -29,12 +29,15 @@ class DetailsPage extends StatelessWidget { Padding( padding: const EdgeInsets.only( bottom: 16.0, top: 8.0, left: 8.0, right: 8.0), - child: ClipRRect( - borderRadius: BorderRadius.circular(10.0), - child: Image.network( - data.imageUrl ?? '', - fit: BoxFit.cover, - ))), + child: SizedBox( + width: double.infinity, + child: ClipRRect( + borderRadius: BorderRadius.circular(10.0), + child: Image.network( + data.imageUrl ?? '', + fit: BoxFit.cover, + )), + )), Padding( padding: const EdgeInsets.only( bottom: 4.0, top: 8.0, left: 8.0, right: 8.0),