mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 14:19:40 +00:00
added product api and model
This commit is contained in:
26
lib/services/product_api.dart
Normal file
26
lib/services/product_api.dart
Normal file
@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/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 [];
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user