6 починка пагинации
This commit is contained in:
parent
f96bd1b426
commit
9034612747
@ -8,9 +8,10 @@ part 'foods_dto.g.dart';
|
|||||||
@JsonSerializable(createToJson: false)
|
@JsonSerializable(createToJson: false)
|
||||||
class FoodsDto {
|
class FoodsDto {
|
||||||
final List<FoodDataDto>? foods;
|
final List<FoodDataDto>? foods;
|
||||||
final MetaDto? meta;
|
final int? currentPage;
|
||||||
|
final int? totalPages;
|
||||||
|
|
||||||
const FoodsDto({this.foods, this.meta});
|
const FoodsDto({this.foods, this.currentPage, this.totalPages});
|
||||||
|
|
||||||
factory FoodsDto.fromJson(Map<String, dynamic> json) => _$FoodsDtoFromJson(json);
|
factory FoodsDto.fromJson(Map<String, dynamic> json) => _$FoodsDtoFromJson(json);
|
||||||
|
|
||||||
@ -27,23 +28,3 @@ class FoodDataDto {
|
|||||||
|
|
||||||
factory FoodDataDto.fromJson(Map<String, dynamic> json) => _$FoodDataDtoFromJson(json);
|
factory FoodDataDto.fromJson(Map<String, dynamic> json) => _$FoodDataDtoFromJson(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class MetaDto {
|
|
||||||
final PaginationDto? pagination;
|
|
||||||
|
|
||||||
const MetaDto({this.pagination});
|
|
||||||
|
|
||||||
factory MetaDto.fromJson(Map<String, dynamic> json) => _$MetaDtoFromJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonSerializable(createToJson: false)
|
|
||||||
class PaginationDto {
|
|
||||||
final int? current;
|
|
||||||
final int? next;
|
|
||||||
final int? last;
|
|
||||||
|
|
||||||
const PaginationDto({this.current, this.next, this.last});
|
|
||||||
|
|
||||||
factory PaginationDto.fromJson(Map<String, dynamic> json) => _$PaginationDtoFromJson(json);
|
|
||||||
}
|
|
@ -10,9 +10,8 @@ FoodsDto _$FoodsDtoFromJson(Map<String, dynamic> json) => FoodsDto(
|
|||||||
foods: (json['foods'] as List<dynamic>?)
|
foods: (json['foods'] as List<dynamic>?)
|
||||||
?.map((e) => FoodDataDto.fromJson(e as Map<String, dynamic>))
|
?.map((e) => FoodDataDto.fromJson(e as Map<String, dynamic>))
|
||||||
.toList(),
|
.toList(),
|
||||||
meta: json['meta'] == null
|
currentPage: (json['currentPage'] as num?)?.toInt(),
|
||||||
? null
|
totalPages: (json['totalPages'] as num?)?.toInt(),
|
||||||
: MetaDto.fromJson(json['meta'] as Map<String, dynamic>),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
FoodDataDto _$FoodDataDtoFromJson(Map<String, dynamic> json) => FoodDataDto(
|
FoodDataDto _$FoodDataDtoFromJson(Map<String, dynamic> json) => FoodDataDto(
|
||||||
@ -21,16 +20,3 @@ FoodDataDto _$FoodDataDtoFromJson(Map<String, dynamic> json) => FoodDataDto(
|
|||||||
description: json['description'] as String?,
|
description: json['description'] as String?,
|
||||||
image: json['image'] as String?,
|
image: json['image'] as String?,
|
||||||
);
|
);
|
||||||
|
|
||||||
MetaDto _$MetaDtoFromJson(Map<String, dynamic> json) => MetaDto(
|
|
||||||
pagination: json['pagination'] == null
|
|
||||||
? null
|
|
||||||
: PaginationDto.fromJson(json['pagination'] as Map<String, dynamic>),
|
|
||||||
);
|
|
||||||
|
|
||||||
PaginationDto _$PaginationDtoFromJson(Map<String, dynamic> json) =>
|
|
||||||
PaginationDto(
|
|
||||||
current: (json['current'] as num?)?.toInt(),
|
|
||||||
next: (json['next'] as num?)?.toInt(),
|
|
||||||
last: (json['last'] as num?)?.toInt(),
|
|
||||||
);
|
|
||||||
|
@ -12,8 +12,16 @@ extension CharacterDataDtoToModel on FoodDataDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension CharactersDtoToModel on FoodsDto {
|
extension CharactersDtoToModel on FoodsDto {
|
||||||
HomeData toDomain() => HomeData(
|
HomeData toDomain() {
|
||||||
|
int? nextPage = currentPage;
|
||||||
|
|
||||||
|
if (currentPage != null && totalPages != null && totalPages! > currentPage!) {
|
||||||
|
nextPage = currentPage! + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HomeData(
|
||||||
data: foods?.map((e) => e.toDomain()).toList(),
|
data: foods?.map((e) => e.toDomain()).toList(),
|
||||||
nextPage: meta?.pagination?.next,
|
nextPage: nextPage,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user