ура пагинация тоже
This commit is contained in:
parent
037ed69a5c
commit
96b93be954
@ -12,7 +12,7 @@ class Debounce {
|
|||||||
|
|
||||||
static void run(
|
static void run(
|
||||||
VoidCallback action, {
|
VoidCallback action, {
|
||||||
Duration delay = const Duration(milliseconds: 500),
|
Duration delay = const Duration(milliseconds: 2000),
|
||||||
}) {
|
}) {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
_timer = Timer(delay, action);
|
_timer = Timer(delay, action);
|
||||||
|
@ -17,11 +17,14 @@ class FilmsRepository {
|
|||||||
static const String _baseUrl = 'https://kinopoiskapiunofficial.tech';
|
static const String _baseUrl = 'https://kinopoiskapiunofficial.tech';
|
||||||
static const String _apiKey = '67c830e4-b979-48ba-903d-a00c8f96fd4b';
|
static const String _apiKey = '67c830e4-b979-48ba-903d-a00c8f96fd4b';
|
||||||
|
|
||||||
|
List<FilmDataDto> _allFilms = [];
|
||||||
|
List<SearchDataDto> _someFilms = [];
|
||||||
|
|
||||||
Future<HomeData?> loadData({
|
Future<HomeData?> loadData({
|
||||||
OnErrorCallback? onError,
|
OnErrorCallback? onError,
|
||||||
String? q,
|
String? q,
|
||||||
int page = 1,
|
int page = 1,
|
||||||
int pageSize = 7,
|
int pageSize = 5,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
String url = '$_baseUrl/api/v2.2/films/premieres';
|
String url = '$_baseUrl/api/v2.2/films/premieres';
|
||||||
@ -30,19 +33,41 @@ class FilmsRepository {
|
|||||||
url = '$_baseUrl/api/v2.1/films/search-by-keyword';
|
url = '$_baseUrl/api/v2.1/films/search-by-keyword';
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> months = ['JANUARY'];
|
final String month = (() {
|
||||||
|
switch (DateTime.now().month) {
|
||||||
|
case 1:
|
||||||
|
return 'JANUARY';
|
||||||
|
case 2:
|
||||||
|
return 'FEBRUARY';
|
||||||
|
case 3:
|
||||||
|
return 'MARCH';
|
||||||
|
case 4:
|
||||||
|
return 'APRIL';
|
||||||
|
case 5:
|
||||||
|
return 'MAY';
|
||||||
|
case 6:
|
||||||
|
return 'JUNE';
|
||||||
|
case 7:
|
||||||
|
return 'JULY';
|
||||||
|
case 8:
|
||||||
|
return 'AUGUST';
|
||||||
|
case 9:
|
||||||
|
return 'SEPTEMBER';
|
||||||
|
case 10:
|
||||||
|
return 'OCTOBER';
|
||||||
|
case 11:
|
||||||
|
return 'NOVEMBER';
|
||||||
|
case 12:
|
||||||
|
return 'DECEMBER';
|
||||||
|
default:
|
||||||
|
throw Exception('Invalid month');
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
final List<FilmDataDto> allFilms = [];
|
final Response<dynamic> response = await _dio.get<Map<dynamic, dynamic>>(
|
||||||
final List<SearchDataDto> someFilms = [];
|
|
||||||
|
|
||||||
for (final month in months) {
|
|
||||||
final Response<dynamic> response =
|
|
||||||
await _dio.get<Map<dynamic, dynamic>>(
|
|
||||||
url,
|
url,
|
||||||
queryParameters: {
|
queryParameters: {
|
||||||
'year': DateTime
|
'year': DateTime.now().year,
|
||||||
.now()
|
|
||||||
.year,
|
|
||||||
'month': month,
|
'month': month,
|
||||||
'keyword': q,
|
'keyword': q,
|
||||||
'page': page,
|
'page': page,
|
||||||
@ -60,22 +85,21 @@ class FilmsRepository {
|
|||||||
if (q != null && q.isNotEmpty) {
|
if (q != null && q.isNotEmpty) {
|
||||||
final SearchDto dtos =
|
final SearchDto dtos =
|
||||||
SearchDto.fromJson(response.data as Map<String, dynamic>);
|
SearchDto.fromJson(response.data as Map<String, dynamic>);
|
||||||
someFilms.addAll(dtos.films!);
|
_someFilms.addAll(dtos.films!);
|
||||||
} else {
|
} else {
|
||||||
final FilmsDto dto =
|
final FilmsDto dto =
|
||||||
FilmsDto.fromJson(response.data as Map<String, dynamic>);
|
FilmsDto.fromJson(response.data as Map<String, dynamic>);
|
||||||
allFilms.addAll(dto.items!);
|
_allFilms.addAll(dto.items!);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
onError?.call('Request failed with status: ${response.statusCode}');
|
onError?.call('Request failed with status: ${response.statusCode}');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final HomeData data = HomeData(
|
final HomeData data = HomeData(
|
||||||
data: q != null && q.isNotEmpty
|
data: q != null && q.isNotEmpty
|
||||||
? someFilms.map((e) => e.toDomain()).toList()
|
? _someFilms.skip((page - 1) * pageSize).take(pageSize).map((e) => e.toDomain()).toList()
|
||||||
: allFilms.map((e) => e.toDomain()).toList(),
|
: _allFilms.skip((page - 1) * pageSize).take(pageSize).map((e) => e.toDomain()).toList(),
|
||||||
nextPage: page + 1, // Увеличиваем номер страницы для следующего запроса
|
nextPage: page + 1, // Увеличиваем номер страницы для следующего запроса
|
||||||
);
|
);
|
||||||
|
|
||||||
|
52
pubspec.lock
52
pubspec.lock
@ -34,10 +34,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: args
|
name: args
|
||||||
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
|
sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.5.0"
|
version: "2.6.0"
|
||||||
async:
|
async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -162,10 +162,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: code_builder
|
name: code_builder
|
||||||
sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37
|
sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.10.0"
|
version: "4.10.1"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -178,10 +178,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: convert
|
name: convert
|
||||||
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
|
sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.1.1"
|
version: "3.1.2"
|
||||||
copy_with_extension:
|
copy_with_extension:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -202,10 +202,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: crypto
|
name: crypto
|
||||||
sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27
|
sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.5"
|
version: "3.0.6"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -242,10 +242,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: equatable
|
name: equatable
|
||||||
sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2
|
sha256: "567c64b3cb4cf82397aac55f4f0cbd3ca20d77c6c03bedbc4ceaddc08904aef7"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.5"
|
version: "2.0.7"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -266,18 +266,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: file
|
name: file
|
||||||
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
|
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "7.0.0"
|
version: "7.0.1"
|
||||||
fixnum:
|
fixnum:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: fixnum
|
name: fixnum
|
||||||
sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1"
|
sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.1"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -422,10 +422,10 @@ packages:
|
|||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: json_serializable
|
name: json_serializable
|
||||||
sha256: ea1432d167339ea9b5bb153f0571d0039607a873d6e04e0117af043f14a1fd4b
|
sha256: c2fcb3920cf2b6ae6845954186420fca40bc0a8abcc84903b7801f17d7050d7c
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.8.0"
|
version: "6.9.0"
|
||||||
leak_tracker:
|
leak_tracker:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -462,10 +462,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: logging
|
name: logging
|
||||||
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
|
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.3.0"
|
||||||
macros:
|
macros:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -694,10 +694,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: shelf_web_socket
|
name: shelf_web_socket
|
||||||
sha256: "073c147238594ecd0d193f3456a5fe91c4b0abbcc68bf5cd95b36c4e194ac611"
|
sha256: cc36c297b52866d203dbf9332263c94becc2fe0ceaa9681d07b6ef9807023b67
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.0"
|
version: "2.0.1"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -787,18 +787,18 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: typed_data
|
name: typed_data
|
||||||
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
|
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.2"
|
version: "1.4.0"
|
||||||
vector_graphics:
|
vector_graphics:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vector_graphics
|
name: vector_graphics
|
||||||
sha256: "773c9522d66d523e1c7b25dfb95cc91c26a1e17b107039cfe147285e92de7878"
|
sha256: "27d5fefe86fb9aace4a9f8375b56b3c292b64d8c04510df230f849850d912cb7"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.14"
|
version: "1.1.15"
|
||||||
vector_graphics_codec:
|
vector_graphics_codec:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -811,10 +811,10 @@ packages:
|
|||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vector_graphics_compiler
|
name: vector_graphics_compiler
|
||||||
sha256: ab9ff38fc771e9ee1139320adbe3d18a60327370c218c60752068ebee4b49ab1
|
sha256: "1b4b9e706a10294258727674a340ae0d6e64a7231980f9f9a3d12e4b42407aad"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.15"
|
version: "1.1.16"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user