updateProfile method

Future<CkAuthResult<TProfile?>> updateProfile({
  1. Map<String, dynamic>? formFields,
  2. Map<String, dynamic>? files,
  3. Map<String, dynamic>? jsonBody,
})

Updates the profile on the server using the configured profileUpdateUrl.

Implementation

Future<CkAuthResult<TProfile?>> updateProfile({
  Map<String, dynamic>? formFields,
  Map<String, dynamic>? files,
  Map<String, dynamic>? jsonBody,
}) {
  return loadingController.wrap(CkAuthLoadingType.updateProfile, () async {
    if (config.mockAuth) {
      return const CkAuthResult.success(data: null, statusCode: 200);
    }
    final result = await _profileExtractor.updateProfileRemote(
      url: config.endpoints.updateProfile,
      method: config.endpoints.updateProfileMethod,
      formFields: formFields,
      files: files,
      jsonBody: jsonBody,
    );

    if (result.isSuccess) {
      final fetchResult = await fetchProfile();
      if (fetchResult.isSuccess && fetchResult.data != null) {
        return CkAuthResult.success(
          data: fetchResult.data,
          statusCode: result.statusCode,
          rawResponse: result.rawResponse,
        );
      }
    }

    return result;
  });
}