postMethod method
Sends an HTTP POST request to the specified url with optional headers
and request body.
Returns a Future that completes with a (int, Map<String, dynamic>)
containing the status code and the response data.
Throws an exception if the request fails.
Example usage:
var response = await ApiMethods().postMethod(url: "https://api.example.com/data", body: jsonEncode({"key": "value"}));
Implementation
Future<(int statusCode, Map<String, dynamic> data)> postMethod({
String? url,
Map<String, String>? headers,
var body,
}) async {
try {
var response = await http.post(
Uri.parse(url ?? ""),
headers: headers,
body: body,
);
return _handleResponse(response);
} catch (error, stackTrace) {
throw (error, stackTrace);
}
}