diff --git a/lib/data/dtos/character_dto.dart b/lib/data/dtos/character_dto.dart index 57abdd7..68aec1a 100644 --- a/lib/data/dtos/character_dto.dart +++ b/lib/data/dtos/character_dto.dart @@ -6,11 +6,15 @@ part 'character_dto.g.dart'; class CharactersDto { @JsonKey(name: 'characters') final List? 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 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 json) => _$CharacterDataAttributesDtoFromJson(json); -} - -@JsonSerializable(createToJson: false) -class MetaDto { - final PaginationDto? pagination; - const MetaDto({this.pagination}); - factory MetaDto.fromJson(Map 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 json) => _$PaginationDtoFromJson(json); -} +} \ No newline at end of file diff --git a/lib/data/mappers/character_mapper.dart b/lib/data/mappers/character_mapper.dart index 51b4f30..3bcef11 100644 --- a/lib/data/mappers/character_mapper.dart +++ b/lib/data/mappers/character_mapper.dart @@ -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'; } } diff --git a/lib/domain/models/card.dart b/lib/domain/models/card.dart index 033fd76..db9f276 100644 --- a/lib/domain/models/card.dart +++ b/lib/domain/models/card.dart @@ -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, }); } diff --git a/lib/presentation/home_page/card.dart b/lib/presentation/home_page/card.dart index 3ce7aa8..6d85612 100644 --- a/lib/presentation/home_page/card.dart +++ b/lib/presentation/home_page/card.dart @@ -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, - ), ], ), ), diff --git a/lib/presentation/home_page/home_page.dart b/lib/presentation/home_page/home_page.dart index 2cf1fc6..a7676d8 100644 --- a/lib/presentation/home_page/home_page.dart +++ b/lib/presentation/home_page/home_page.dart @@ -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(); if (!bloc.state.isPaginationLoading) { @@ -87,6 +87,7 @@ class _BodyState extends State<_Body> { @override void dispose() { searchController.dispose(); + scrollController.dispose(); super.dispose(); } diff --git a/lib/repositories/naruto.dart b/lib/repositories/naruto.dart index fc44875..a966a8d 100644 --- a/lib/repositories/naruto.dart +++ b/lib/repositories/naruto.dart @@ -20,9 +20,10 @@ class NarutoRepository extends ApiInterface { Future loadData({ OnErrorCallback? onError, String? q, - int page = 1, + int? page = 1, int pageSize = 8, }) async { + const String url = '$_baseUrl/characters'; try { final Response response = await _dio.get>(