6 до починки пагинации

This commit is contained in:
GokaPek 2024-10-20 12:08:42 +04:00
parent 6c7b2245c9
commit f96bd1b426
3 changed files with 10 additions and 11 deletions

View File

@ -48,7 +48,7 @@ class BodyState extends State<Body> {
}
void _onNextPageListener() {
if (scrollController.offset > scrollController.position.maxScrollExtent) {
if (scrollController.offset >= scrollController.position.maxScrollExtent) {
final bloc = context.read<HomeBloc>();
if (!bloc.state.isPaginationLoading) {
bloc.add(HomeLoadDataEvent(
@ -59,6 +59,7 @@ class BodyState extends State<Body> {
}
}
@override
void dispose() {
searchController.dispose();
@ -137,7 +138,7 @@ class BodyState extends State<Body> {
WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'$title ${isLiked ? 'liked!' : 'disliked :('}',
'$title ${isLiked ? 'liked!' : 'disliked'}',
style: Theme.of(context).textTheme.bodyLarge,
),
backgroundColor: Colors.redAccent,

View File

@ -10,6 +10,9 @@ FoodsDto _$FoodsDtoFromJson(Map<String, dynamic> json) => FoodsDto(
foods: (json['foods'] as List<dynamic>?)
?.map((e) => FoodDataDto.fromJson(e as Map<String, dynamic>))
.toList(),
meta: json['meta'] == null
? null
: MetaDto.fromJson(json['meta'] as Map<String, dynamic>),
);
FoodDataDto _$FoodDataDtoFromJson(Map<String, dynamic> json) => FoodDataDto(

View File

@ -20,17 +20,12 @@ class FoodRepository extends ApiInterface {
static const String _baseUrl = 'https://api.nal.usda.gov';
@override
Future<HomeData?> loadData({String? q, int page = 1, int pageSize = 5}) async {
Future<HomeData?> loadData({String? q, int page = 1, int pageSize = 10}) async {
try {
final String searchQuery = q ?? 'food'; // Используем 'food' как значение по умолчанию
final String url = '$_baseUrl/fdc/v1/foods/search?api_key=91xPcWwfSGljSRMuoS8IH0GP4hM9QqwwtgSzqJMw&query=$searchQuery&pageSize=10';
final String searchQuery = q ?? ''; // Используем 'food' как значение по умолчанию
final String url = '$_baseUrl/fdc/v1/foods/search?api_key=91xPcWwfSGljSRMuoS8IH0GP4hM9QqwwtgSzqJMw&query=$searchQuery&pageNumber=$page&pageSize=$pageSize';
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(url,
queryParameters: {
'page[number]': page,
'page[size]': pageSize,
}
);
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(url);
final FoodsDto dto = FoodsDto.fromJson(response.data as Map<String, dynamic>);
// final List<CardData>? data = dto.foods?.map((e) => e.toDomain()).toList();