lab5 готова без поиска, надо менять апишку

This commit is contained in:
antoc0der 2024-09-25 19:28:26 +04:00
parent 02c53b7e40
commit e7e2628e8b
5 changed files with 18 additions and 32 deletions

View File

@ -2,20 +2,12 @@ import 'package:json_annotation/json_annotation.dart';
part 'news_dto.g.dart'; part 'news_dto.g.dart';
@JsonSerializable(createToJson: false) @JsonSerializable(createToJson: false)
class NewsDto{ class NewsDto{
final List<NewDataDto>? data; @JsonKey(name: 'Главное')
final List<NewAttributesDataDto>? data;
const NewsDto({this.data}); const NewsDto({this.data});
factory NewsDto.fromJson(Map<String, dynamic> json) => _$NewsDtoFromJson(json); factory NewsDto.fromJson(Map<String, dynamic> 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<String, dynamic> json) => _$NewDataDtoFromJson(json);
}
@JsonSerializable(createToJson: false) @JsonSerializable(createToJson: false)
class NewAttributesDataDto{ class NewAttributesDataDto{
@ -26,5 +18,4 @@ class NewAttributesDataDto{
const NewAttributesDataDto({this.title, this.summary, this.imagelink }); const NewAttributesDataDto({this.title, this.summary, this.imagelink });
factory NewAttributesDataDto.fromJson(Map<String, dynamic> json) => _$NewAttributesDataDtoFromJson(json); factory NewAttributesDataDto.fromJson(Map<String, dynamic> json) => _$NewAttributesDataDtoFromJson(json);
} }

View File

@ -7,19 +7,11 @@ part of 'news_dto.dart';
// ************************************************************************** // **************************************************************************
NewsDto _$NewsDtoFromJson(Map<String, dynamic> json) => NewsDto( NewsDto _$NewsDtoFromJson(Map<String, dynamic> json) => NewsDto(
data: (json['data'] as List<dynamic>?) data: (json['Главное'] as List<dynamic>?)
?.map((e) => NewDataDto.fromJson(e as Map<String, dynamic>)) ?.map((e) => NewAttributesDataDto.fromJson(e as Map<String, dynamic>))
.toList(), .toList(),
); );
NewDataDto _$NewDataDtoFromJson(Map<String, dynamic> json) => NewDataDto(
id: json['id'] as String?,
type: json['type'] as String?,
attributes: json['attributes'] == null
? null
: NewAttributesDataDto.fromJson(
json['attributes'] as Map<String, dynamic>),
);
NewAttributesDataDto _$NewAttributesDataDtoFromJson( NewAttributesDataDto _$NewAttributesDataDtoFromJson(
Map<String, dynamic> json) => Map<String, dynamic> json) =>

View File

@ -1,10 +1,10 @@
import 'package:pmu/data/dtos/news_dto.dart'; import 'package:pmu/data/dtos/news_dto.dart';
import 'package:pmu/domain/models/card.dart'; import 'package:pmu/domain/models/card.dart';
extension NewDataDtoToModel on NewDataDto{ extension NewDataDtoToModel on NewAttributesDataDto{
CardData toDomain() => CardData( CardData toDomain() => CardData(
text: attributes?.title ?? 'UNKNOWN', text: title ?? 'UNKNOWN',
imageUrl: attributes?.imagelink, imageUrl: imagelink,
descText: attributes?.summary ?? 'NOTHING', descText: summary ?? 'NOTHING',
); );
} }

View File

@ -20,7 +20,7 @@ class BbcRepository extends ApiInterface {
const String url = '$_baseUrl/news?lang=russian'; const String url = '$_baseUrl/news?lang=russian';
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>( final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
url, url,
// queryParameters: q != null ? {'filter[name_cont]': q} : null, //queryParameters: q != null ? {'filter[name_cont]': q} : null,
); );
final NewsDto dto = final NewsDto dto =
NewsDto.fromJson(response.data as Map<String, dynamic>); NewsDto.fromJson(response.data as Map<String, dynamic>);

View File

@ -29,12 +29,15 @@ class DetailsPage extends StatelessWidget {
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
bottom: 16.0, top: 8.0, left: 8.0, right: 8.0), bottom: 16.0, top: 8.0, left: 8.0, right: 8.0),
child: ClipRRect( child: SizedBox(
borderRadius: BorderRadius.circular(10.0), width: double.infinity,
child: Image.network( child: ClipRRect(
data.imageUrl ?? '', borderRadius: BorderRadius.circular(10.0),
fit: BoxFit.cover, child: Image.network(
))), data.imageUrl ?? '',
fit: BoxFit.cover,
)),
)),
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
bottom: 4.0, top: 8.0, left: 8.0, right: 8.0), bottom: 4.0, top: 8.0, left: 8.0, right: 8.0),