теперь с кривой пагинацией
This commit is contained in:
parent
224097153a
commit
f1d02a3b0f
@ -6,11 +6,15 @@ part 'character_dto.g.dart';
|
||||
class CharactersDto {
|
||||
@JsonKey(name: 'characters')
|
||||
final List<CharacterDataDto>? data;
|
||||
final MetaDto? meta;
|
||||
final int? currentPage;
|
||||
final int? pageSize;
|
||||
final int? total;
|
||||
|
||||
const CharactersDto({
|
||||
this.data,
|
||||
this.meta,
|
||||
this.currentPage,
|
||||
this.pageSize,
|
||||
this.total,
|
||||
});
|
||||
|
||||
factory CharactersDto.fromJson(Map<String, dynamic> json) =>
|
||||
@ -35,25 +39,9 @@ class CharacterDataDto {
|
||||
class CharacterDataAttributesDto {
|
||||
final String? birthdate;
|
||||
final String? sex;
|
||||
final String? clan;
|
||||
|
||||
const CharacterDataAttributesDto({this.birthdate, this.sex, this.clan});
|
||||
const CharacterDataAttributesDto({this.birthdate, this.sex});
|
||||
|
||||
factory CharacterDataAttributesDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$CharacterDataAttributesDtoFromJson(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);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ const _imagePlaceHolder =
|
||||
extension CharactersDtoToModel on CharactersDto {
|
||||
HomeData toDomain() => HomeData(
|
||||
data: data?.map((e) => e.toDomain()).toList(),
|
||||
nextPage: meta?.pagination?.next,
|
||||
nextPage: (currentPage! * pageSize! < total! ? currentPage! + 1 : null),
|
||||
);
|
||||
}
|
||||
|
||||
@ -17,13 +17,11 @@ extension CharacterDataDtoToModel on CharacterDataDto {
|
||||
CardData toDomain() => CardData(
|
||||
name ?? 'Unknown',
|
||||
_makeDescriptionText(),
|
||||
clan: 'clan: ${attributes != null ? (attributes?.clan ?? 'unknown') : 'unknown'}',
|
||||
imageUrl: '${(images != null && images!.length > 0) ? (images?[0] ?? _imagePlaceHolder) : _imagePlaceHolder}'
|
||||
);
|
||||
|
||||
String _makeDescriptionText() {
|
||||
return 'birthdate: ${attributes != null ? (attributes?.birthdate ?? 'unknown') : 'unknown'}\n'
|
||||
'sex: ${attributes != null ? (attributes?.sex ?? 'unknown') : 'unknown'}\n'
|
||||
'clan: ${attributes != null ? (attributes?.clan ?? 'unknown') : 'unknown'}';
|
||||
'sex: ${attributes != null ? (attributes?.sex ?? 'unknown') : 'unknown'}\n';
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,11 @@ import 'package:flutter/material.dart';
|
||||
class CardData {
|
||||
final String name;
|
||||
final String descriptionText;
|
||||
final String clan;
|
||||
final String imageUrl;
|
||||
|
||||
CardData(
|
||||
this.name,
|
||||
this.descriptionText,{
|
||||
required this.imageUrl,
|
||||
required this.clan,
|
||||
});
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ typedef OnLikeCall = void Function(String Title, bool isLiked);
|
||||
class _Card extends StatefulWidget {
|
||||
final String name;
|
||||
final String descriptionText;
|
||||
final String clan;
|
||||
final String imageUrl;
|
||||
final Color color;
|
||||
final OnLikeCall? onLike;
|
||||
@ -14,7 +13,6 @@ class _Card extends StatefulWidget {
|
||||
const _Card(
|
||||
this.name,
|
||||
this.descriptionText, {
|
||||
required this.clan,
|
||||
required this.imageUrl,
|
||||
this.color = Colors.white70,
|
||||
this.onLike,
|
||||
@ -29,7 +27,6 @@ class _Card extends StatefulWidget {
|
||||
_Card(
|
||||
data.name,
|
||||
data.descriptionText,
|
||||
clan: data.clan,
|
||||
imageUrl: data.imageUrl,
|
||||
color: Colors.white70,
|
||||
onLike: onLike,
|
||||
@ -106,10 +103,6 @@ class _CardState extends State<_Card> {
|
||||
widget.name,
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
Text(
|
||||
widget.clan,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -72,7 +72,7 @@ class _BodyState extends State<_Body> {
|
||||
}
|
||||
|
||||
void _onNextPageListener() {
|
||||
if (scrollController.offset > scrollController.position.maxScrollExtent) {
|
||||
if (scrollController.offset >= scrollController.position.maxScrollExtent) {
|
||||
// preventing multiple pagination request on multiple swipes
|
||||
final bloc = context.read<HomeBloc>();
|
||||
if (!bloc.state.isPaginationLoading) {
|
||||
@ -87,6 +87,7 @@ class _BodyState extends State<_Body> {
|
||||
@override
|
||||
void dispose() {
|
||||
searchController.dispose();
|
||||
scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,10 @@ class NarutoRepository extends ApiInterface {
|
||||
Future<HomeData?> loadData({
|
||||
OnErrorCallback? onError,
|
||||
String? q,
|
||||
int page = 1,
|
||||
int? page = 1,
|
||||
int pageSize = 8,
|
||||
}) async {
|
||||
|
||||
const String url = '$_baseUrl/characters';
|
||||
try {
|
||||
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
||||
|
Loading…
Reference in New Issue
Block a user