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';
@JsonSerializable(createToJson: false)
class NewsDto{
final List<NewDataDto>? data;
@JsonKey(name: 'Главное')
final List<NewAttributesDataDto>? data;
const NewsDto({this.data});
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)
class NewAttributesDataDto{
@ -26,5 +18,4 @@ class NewAttributesDataDto{
const NewAttributesDataDto({this.title, this.summary, this.imagelink });
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(
data: (json['data'] as List<dynamic>?)
?.map((e) => NewDataDto.fromJson(e as Map<String, dynamic>))
data: (json['Главное'] as List<dynamic>?)
?.map((e) => NewAttributesDataDto.fromJson(e as Map<String, dynamic>))
.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(
Map<String, dynamic> json) =>

View File

@ -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',
);
}

View File

@ -20,7 +20,7 @@ class BbcRepository extends ApiInterface {
const String url = '$_baseUrl/news?lang=russian';
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
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<String, dynamic>);

View File

@ -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),