Add: Getting items by its ids

This commit is contained in:
2024-05-23 22:12:07 +03:00
parent d6f64465b3
commit 0438a6feec
3 changed files with 34 additions and 23 deletions

View File

@@ -37,15 +37,19 @@ Future<List<GymItem>> getItemsByIds(
BuildContext context, List<String> ids) async {
final token = context.read<GymLinkProvider>().token;
if (token != '') {
if (ids.isEmpty) {
return [];
}
final Uri url =
Uri.http('gymlink.freemyip.com:8080', 'api/product/get-products');
try {
final response = await http.post(url,
headers: {
'Authorization': 'Bearer $token',
'Content-Type': 'application/json'
},
body: jsonEncode(ids.toList()));
if (response.statusCode == 200) {
body: jsonEncode({"ids": ids}));
if (response.statusCode == 201) {
final data =
jsonDecode(utf8.decode(response.bodyBytes)) as List<dynamic>;
final items = data.map((e) => GymItem.fromJson(e)).toList();