post static method
Future<CommonResponse>
post()
Implementation
static Future<CommonResponse> post(
String partUrl,
dynamic body,
void Function(CommonResponse) successCompletion,
void Function(CommonResponse) errCompletion,
bool isMultipart,
String? token) async {
late CommonResponse commonResponse;
Dio dio = initDio(partUrl, false);
await dio
.post("",
options: token != null
? Options(
contentType: Headers.jsonContentType,
headers: {"Authorization": "Token $token"})
: Options(contentType: Headers.jsonContentType),
data: body)
.then((response) {
debugPrint("res ==== " + response.toString());
commonResponse = CommonResponse.fromJson(response.data);
if (commonResponse.success!) {
successCompletion(commonResponse);
} else {
errCompletion(commonResponse);
}
}).catchError((e) {
print(e);
if (e is DioError) {
print(e.response?.statusCode);
commonResponse = CommonResponse.fromJson(e.response?.data);
debugPrint("err ==== ${e.response}");
errCompletion(commonResponse);
}
});
return commonResponse;
}