getGroupChannelAvatarComponent method

SBUAvatarComponent getGroupChannelAvatarComponent({
  1. required bool isLightTheme,
  2. required double size,
  3. required GroupChannel channel,
})
inherited

Implementation

SBUAvatarComponent getGroupChannelAvatarComponent({
  required bool isLightTheme,
  required double size,
  required GroupChannel channel,
}) {
  final List<String> imageUrls = [];
  final sortedMembers = sortMembersByNickname(channel.members);
  final isDefaultCoverUrl = channel.coverUrl
      .startsWith('https://static.sendbird.com/sample/cover/cover_');

  if (channel.coverUrl.isNotEmpty && isDefaultCoverUrl == false) {
    imageUrls.add(channel.coverUrl);
  } else {
    for (int i = 0; i < sortedMembers.length; i++) {
      final member = sortedMembers[i];
      if (member.userId != SendbirdChat.currentUser?.userId) {
        imageUrls.add(member.profileUrl);
        if (imageUrls.length == 4) {
          break;
        }
      }
    }
  }

  SBUIconComponent? icon = imageUrls.isEmpty
      ? SBUIconComponent(
          iconSize: size * 0.57142857142,
          iconData: SBUIcons.user,
          iconColor: isLightTheme
              ? SBUColors.darkThemeTextHighEmphasis
              : SBUColors.lightThemeTextHighEmphasis,
        )
      : null;
  Color? backgroundColor = imageUrls.isEmpty ? SBUColors.background300 : null;

  if (channel.isBroadcast) {
    imageUrls.clear();
    icon = SBUIconComponent(
      iconSize: size * 0.57142857142,
      iconData: SBUIcons.broadcast,
      iconColor: isLightTheme
          ? SBUColors.darkThemeTextHighEmphasis
          : SBUColors.lightThemeTextHighEmphasis,
    );
    backgroundColor =
        isLightTheme ? SBUColors.secondaryMain : SBUColors.secondaryLight;
  }

  return SBUAvatarComponent(
    width: size,
    height: size,
    icon: icon,
    backgroundColor: backgroundColor,
    imageUrls: imageUrls,
  );
}