73 lines
2.2 KiB
Dart
73 lines
2.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:cheminova/models/single_get_order_model.dart';
|
|
import 'package:dio/dio.dart';
|
|
|
|
import '../models/rd_get_order_model.dart';
|
|
import '../utils/api_urls.dart';
|
|
import '../utils/common_api_service.dart';
|
|
import '../utils/show_snackbar.dart';
|
|
|
|
class GetSingleProductService{
|
|
// Future<SingleGetOrderModel?> getSingleOrder(String token,String orderId) async {
|
|
// try {
|
|
// // Ensure the base URL and orderId are concatenated properly
|
|
// String url = "/api/pd-get-single-place-order/$orderId";
|
|
//
|
|
// final response = await commonApiService<SingleGetOrderModel>(
|
|
// method: "GET",
|
|
// url: url,
|
|
// additionalHeaders: {
|
|
// 'Authorization': 'Bearer $token', // Correctly pass the token as 'Bearer <token>'
|
|
// },
|
|
// fromJson: (json) {
|
|
// // Check if the JSON response contains the 'singleOrder' key
|
|
// if (json['singleOrder'] != null) {
|
|
// // Convert the JSON response to a SingleGetOrderModel
|
|
// return SingleGetOrderModel.fromJson(json['singleOrder'] as Map<String, dynamic>);
|
|
// } else {
|
|
// // Handle the case when the order is not found
|
|
// throw Exception("Order not found in response.");
|
|
// }
|
|
// },
|
|
// );
|
|
//
|
|
// return response; // Return the fetched order if successful
|
|
// } catch (e) {
|
|
// // Show a snackbar with the error message
|
|
// showSnackbar(e.toString());
|
|
// return null; // Return null to indicate an error occurred
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
Future<SingleGetOrderModel?> GetsingleOrder(String token,String orderId) async {
|
|
try {
|
|
final response = await Dio().get(
|
|
'https://api.cnapp.co.in/api/pd-get-single-place-order/$orderId',
|
|
|
|
options: Options(
|
|
headers: {
|
|
'Authorization': 'Bearer $token',
|
|
},
|
|
),
|
|
);
|
|
|
|
|
|
if (response.statusCode == 200) {
|
|
final data = response.data['singleOrder'];
|
|
jsonDecode(data);
|
|
return SingleGetOrderModel.fromJson(data);
|
|
} else {
|
|
print('Failed to load order');
|
|
return null;
|
|
}
|
|
} catch (e) {
|
|
print('Error: $e');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
} |