Add: Getting items by its ids
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user