47 lines
1.3 KiB
Dart
47 lines
1.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:cheminova/models/product_stock_model.dart';
|
|
import 'package:dio/dio.dart';
|
|
|
|
import '../utils/api_urls.dart';
|
|
import '../utils/common_api_service.dart';
|
|
import '../utils/show_snackbar.dart';
|
|
|
|
class UpdateStockService{
|
|
|
|
// Function to handle password change functionality
|
|
Future<void> UpdateStockProduct(String token, List<ProductStockModel> stock) async {
|
|
try {
|
|
// Correct API URL with orderId passed in the URL
|
|
final String url = ApiUrls.ProductUpdateStockUrl;
|
|
|
|
// Make the PUT request
|
|
final response = await Dio().put(
|
|
url, // Use the correct URL here
|
|
data: {
|
|
"products": stock, // Send the cancellation reason as JSON
|
|
},
|
|
options: Options(
|
|
headers: {
|
|
'Authorization': 'Bearer $token', // Pass the token in the Authorization header
|
|
'Content-Type': 'application/json', // Set content-type to application/json
|
|
},
|
|
),
|
|
);
|
|
|
|
// Check the response status
|
|
if (response.statusCode == 200) {
|
|
print(response.data);
|
|
print("Stock Update successfully");
|
|
} else {
|
|
throw Exception('Failed to Stock Update');
|
|
}
|
|
} catch (e) {
|
|
// Handle error
|
|
print('Error Stock Update: $e');
|
|
}
|
|
}
|
|
|
|
}
|
|
|