pd-android-app/lib/controller/product_mannual_service.dart

40 lines
1.3 KiB
Dart

import 'package:cheminova/utils/api_urls.dart';
import '../models/product_mannual_model.dart';
import '../utils/common_api_service.dart'; // Replace with your actual common API service import
class ProductMannualService {
// Method to fetch product manuals using an authorization token
Future<List<ProductManualModel>?> getProductManuals(String token) async {
try {
String url = ApiUrls.getProductManualUrl; // Base URL to fetch product manuals
final response = await commonApiService<List<ProductManualModel>>(
method: "GET",
url: url,
additionalHeaders: { // Pass the token here
'Authorization': 'Bearer $token',
},
fromJson: (json) {
if (json['productManuals'] != null) {
// If the productManuals key is present, map the response to a list of ProductManualModel objects
final List<ProductManualModel> productManuals = (json['productManuals'] as List)
.map((manualJson) => ProductManualModel.fromJson(manualJson as Map<String, dynamic>))
.toList();
return productManuals; // Return the list of product manuals
} else {
return [];
}
},
);
return response;
} catch (e) {
print(e.toString());
return null;
}
}
}