updateUserProfileWithFile static method

Future<TPUser?> updateUserProfileWithFile(
  1. String? username,
  2. File? profileImageFile,
  3. Map<String, dynamic>? metaData, {
  4. String? translationLanguage,
  5. dynamic errorCallback(
    1. int? errorCode,
    2. String? errorMessage
    )?,
})

Implementation

static Future<TPUser?> updateUserProfileWithFile(
    String? username,
    File? profileImageFile,
    Map<String, dynamic>? metaData,
    {
      String? translationLanguage,
      Function(int? errorCode, String? errorMessage)? errorCallback
    }) async
{
  if (!_isInitialized(errorCallback: errorCallback)) { return null; }
  //if (!_checkAuthInfo(errorCallback: errorCallback)) { return null; }

  Map<String, dynamic> body = Map.from({});
  if (username != null) { body["username"] = username; }
  if (metaData != null) { body["data"] = metaData; }
  final language = translationLanguage ?? "";
  if(language.isNotEmpty){ body["translationTargetLanguage"] = language; }

  try {
    String url = "/users/update";
    Map<String, dynamic> response = await HttpUtil.postMultipart(url, body, profileImageFile);
    Map<String, dynamic> user = response["user"];
    _mUser = TPUser(user);
    return _mUser;
  } on TPException catch(e) {
    Logger.log("$e");
    if(errorCallback != null) { errorCallback(e.getCode(), e.getMessage()); }
  } catch(e){
    Logger.log("$e");
    if(errorCallback != null) { errorCallback(-1, e.toString()); }
  }
  return null;
}