SmsMessage.fromMap constructor

  1. @visibleForTesting
SmsMessage.fromMap(
  1. Map rawMessage,
  2. List<SmsColumn> columns
)

Do not call this method. This method is visible only for testing.

Implementation

@visibleForTesting
SmsMessage.fromMap(Map rawMessage, List<SmsColumn> columns) {
  final message = Map.castFrom<dynamic, dynamic, String, dynamic>(rawMessage);
  for (var column in columns) {
    debugPrint('Column is ${column._columnName}');
    final value = message[column._columnName];
    switch (column._columnName) {
      case _SmsProjections.ID:
        this.id = int.tryParse(value);
        break;
      case _SmsProjections.ORIGINATING_ADDRESS:
      case _SmsProjections.ADDRESS:
        this.address = value;
        break;
      case _SmsProjections.MESSAGE_BODY:
      case _SmsProjections.BODY:
        this.body = value;
        break;
      case _SmsProjections.DATE:
      case _SmsProjections.TIMESTAMP:
        this.date = int.tryParse(value);
        break;
      case _SmsProjections.DATE_SENT:
        this.dateSent = int.tryParse(value);
        break;
      case _SmsProjections.READ:
        this.read = int.tryParse(value) == 0 ? false : true;
        break;
      case _SmsProjections.SEEN:
        this.seen = int.tryParse(value) == 0 ? false : true;
        break;
      case _SmsProjections.STATUS:
        switch (int.tryParse(value)) {
          case 0:
            this.status = SmsStatus.STATUS_COMPLETE;
            break;
          case 32:
            this.status = SmsStatus.STATUS_PENDING;
            break;
          case 64:
            this.status = SmsStatus.STATUS_FAILED;
            break;
          case -1:
          default:
            this.status = SmsStatus.STATUS_NONE;
            break;
        }
        break;
      case _SmsProjections.SUBJECT:
        this.subject = value;
        break;
      case _SmsProjections.SUBSCRIPTION_ID:
        this.subscriptionId = int.tryParse(value);
        break;
      case _SmsProjections.THREAD_ID:
        this.threadId = int.tryParse(value);
        break;
      case _SmsProjections.TYPE:
        var smsTypeIndex = int.tryParse(value);
        this.type =
            smsTypeIndex != null ? SmsType.values[smsTypeIndex] : null;
        break;
      case _SmsProjections.SERVICE_CENTER_ADDRESS:
        this.serviceCenterAddress = value;
        break;
    }
  }
}