updateProfile method

Future updateProfile({
  1. required UserModel user,
})

Implementation

Future updateProfile({ required UserModel user }) async {
  try {
    String apiUrl = ApiConstantDev.urlApiUpdateProfile;
    var data = user.toJson();
    var jsonData =  jsonEncode(data);
    logCat(jsonData);
    var response = await apiClient.putData(apiUrl: apiUrl, data: data, fName: 'updateProfile');
    if (response.statusCode==HttpStatus.badRequest) {
      final data = jsonDecode(response.body);
      ErrorResponseModel errorResponse = ErrorResponseModel.fromJson(data);
      String msg = ErrorResponseModel.messages(errorResponse: errorResponse);
      DialogView.showAlertDialog( msg: msg);
    }
    if (response.statusCode==HttpStatus.ok) {
      final parsed = jsonDecode(response.body);
      UserModel r = UserModel.fromJson(parsed);
      return r;
    }
  } on SocketException {
    setConnectivity();
  } catch (ex, trace) {
    logError(ex, trace:trace,position: 'updateProfile');
  }
  return null;
}