mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
27 lines
826 B
Dart
27 lines
826 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
|
import 'package:syncrow_web/services/api/http_service.dart';
|
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
|
|
|
class ProductApi {
|
|
Future<List<ProductModel>> fetchProducts() async {
|
|
try {
|
|
final response = await HTTPService().get(
|
|
path: ApiEndpoints.listProducts,
|
|
expectedResponseModel: (json) {
|
|
List<dynamic> jsonData = json['data'];
|
|
|
|
List<ProductModel> productList = jsonData.map((jsonItem) {
|
|
return ProductModel.fromMap(jsonItem);
|
|
}).toList();
|
|
return productList;
|
|
},
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
debugPrint('Error fetching products: $e');
|
|
return [];
|
|
}
|
|
}
|
|
}
|