Add: cart items by its ids

This commit is contained in:
2024-05-23 02:04:37 +03:00
parent e57c7dc0ea
commit d6f64465b3
2 changed files with 34 additions and 1 deletions

View File

@@ -31,3 +31,33 @@ Future<List<GymItem>> getItems(BuildContext context) async {
context.read<GymLinkProvider>().onError();
return [];
}
//FIXME: Сделать, чтоб работало
Future<List<GymItem>> getItemsByIds(
BuildContext context, List<String> ids) async {
final token = context.read<GymLinkProvider>().token;
if (token != '') {
final Uri url =
Uri.http('gymlink.freemyip.com:8080', 'api/product/get-products');
try {
final response = await http.post(url,
headers: {
'Authorization': 'Bearer $token',
},
body: jsonEncode(ids.toList()));
if (response.statusCode == 200) {
final data =
jsonDecode(utf8.decode(response.bodyBytes)) as List<dynamic>;
final items = data.map((e) => GymItem.fromJson(e)).toList();
return items;
}
throw response.body;
} catch (e) {
debugPrint('error: $e');
return await Future.delayed(
const Duration(seconds: 5), () => getItemsByIds(context, ids));
}
}
context.read<GymLinkProvider>().onError();
return [];
}