getAvatarUrl function

Uri getAvatarUrl(
  1. User user, {
  2. API? api,
  3. Hosts? hosts,
})

Returns user's avatar url using hosts settings from api client or provided hosts config.

Throws ArgumentError if hosts and api are both missing.

Implementation

Uri getAvatarUrl(User user, {
  API? api,
  Hosts? hosts,
}) {
  if (hosts == null && api == null)
    throw ArgumentError('Either api or hosts must be provided.');

  hosts ??= api!.hosts;

  return hosts.image.getUri(
    '/avatars/${user.avatarFilename}',
  );
}