getLastCallWidget static method

Widget getLastCallWidget(
  1. Conversation conversation,
  2. BuildContext context,
  3. Color? iconColor
)

Implementation

static Widget getLastCallWidget(
  Conversation conversation,
  BuildContext context,
  Color? iconColor,
) {
  Call call = conversation.lastMessage as Call;
  User? conversationWithUser;
  Group? conversationWithGroup;

  final colorPalette = CometChatThemeHelper.getColorPalette(context);

  if (conversation.conversationWith is User) {
    conversationWithUser = conversation.conversationWith as User;
  } else if (conversation.conversationWith is Group) {
    conversationWithGroup = conversation.conversationWith as Group;
  }

  Widget subtitle = const SizedBox();
  Group? callInitiatorGroup;
  User? callInitiatorUser;
  if (call.callInitiator is User) {
    callInitiatorUser = call.callInitiator as User;
  } else {
    callInitiatorGroup = call.callInitiator as Group;
  }

  if (call.callStatus == CallStatusConstants.ongoing) {
    subtitle = const SizedBox();
  } else if (call.callStatus == CallStatusConstants.ended ||
      call.callStatus == CallStatusConstants.initiated) {
    if ((callInitiatorUser != null &&
            conversationWithUser != null &&
            callInitiatorUser.uid == conversationWithUser.uid) ||
        (callInitiatorGroup != null &&
            conversationWithGroup != null &&
            callInitiatorGroup.guid == conversationWithGroup.guid)) {
      if (call.type == MessageTypeConstants.audio) {
        subtitle = Image.asset(
          AssetConstants.voiceIncoming,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      } else {
        subtitle = Image.asset(
          AssetConstants.videoIncoming,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      }
    } else {
      if (call.type == MessageTypeConstants.audio) {
        subtitle = Image.asset(
          AssetConstants.voiceOutgoing,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      } else {
        subtitle = Image.asset(
          AssetConstants.videoOutgoing,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      }
    }
  } else if (call.callStatus == CallStatusConstants.cancelled ||
      call.callStatus == CallStatusConstants.unanswered ||
      call.callStatus == CallStatusConstants.rejected ||
      call.callStatus == CallStatusConstants.busy) {
    if ((callInitiatorUser != null &&
            conversationWithUser != null &&
            callInitiatorUser.uid == conversationWithUser.uid) ||
        (callInitiatorGroup != null &&
            conversationWithGroup != null &&
            callInitiatorGroup.guid == conversationWithGroup.guid)) {
      if (call.type == MessageTypeConstants.audio) {
        subtitle = Image.asset(
          AssetConstants.audioMissed,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      } else {
        subtitle = Image.asset(
          AssetConstants.videoMissed,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      }
    } else {
      if (call.type == MessageTypeConstants.audio) {
        subtitle = Image.asset(
          AssetConstants.audioMissed,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      } else {
        subtitle = Image.asset(
          AssetConstants.videoMissed,
          package: UIConstants.packageName,
          color: iconColor ?? colorPalette.iconSecondary,
          height: 16,
          width: 16,
        );
      }
    }
  }
  return subtitle;
}