getStatus static method

String getStatus(
  1. BuildContext? context,
  2. CallLog? callLog,
  3. User? loggedInUser
)

getStatus return call status: the label of a call-log row, after a leading space. A missed call (isMissedCallLog) reads "Missed Call"; otherwise an initiated or ended call reads by direction, an ongoing one "Ongoing call", an unanswered or cancelled one (yours) "Unanswered Call" or "Cancelled Call", and a rejected or busy one "Call rejected" or "Call busy" on both sides. A missing log, user or context gives the empty string.

Implementation

static String getStatus(
  BuildContext? context,
  CallLog? callLog,
  User? loggedInUser,
) {
  if (callLog == null || loggedInUser == null) {
    return "";
  }

  if (context == null) {
    return "";
  }

  final translations = Translations.of(context);
  if (isMissedCallLog(callLog, loggedInUser)) {
    return " ${translations.missedCall}";
  }
  final mine = callLogLoggedInUser(callLog, loggedInUser);
  final String callMessageText;
  switch (callLog.status) {
    case CallStatusConstants.initiated:
    case CallStatusConstants.ended:
      callMessageText = mine
          ? translations.outgoingCall
          : translations.incomingCall;
    case CallStatusConstants.ongoing:
      callMessageText = translations.ongoingCall;
    case CallStatusConstants.unanswered:
      callMessageText = translations.unansweredCall;
    case CallStatusConstants.cancelled:
      callMessageText = translations.cancelledCall;
    case CallStatusConstants.rejected:
      callMessageText = translations.callRejected;
    case CallStatusConstants.busy:
      callMessageText = translations.callBusy;
    default:
      callMessageText = "";
  }
  return " $callMessageText";
}