setProfilePictureUrl method

User setProfilePictureUrl(
  1. User user
)

Implementation

User setProfilePictureUrl(User user) {
  if (user.profilePictureUrl == null ||
      user.profilePictureUrl!.startsWith('https://www.gravatar.com')) {
    try {
      // fetch Gravatar image if profile picture is not set
      // or if it is a Gravatar url then simply update it
      // with the latest Gravatar image based on the email
      final gravatar = Gravatar(user.emailAddress);
      final profilePictureUrl = gravatar.imageUrl(size: 128);
      return user.copyWith(
        profilePictureUrl: profilePictureUrl,
      );
    } catch (e) {
      _logger.warning(
        'Failed to fetch Gravatar image for user '
        'with email ${user.emailAddress}: $e',
      );
    }
  }
  return user;
}