query static method

Future<Iterable<CallLogEntry>> query({
  1. int? dateFrom,
  2. int? dateTo,
  3. int? durationFrom,
  4. int? durationTo,
  5. DateTime? dateTimeFrom,
  6. DateTime? dateTimeTo,
  7. String? name,
  8. String? number,
  9. CallType? type,
  10. String? numbertype,
  11. String? numberlabel,
  12. String? cachedNumberType,
  13. String? cachedNumberLabel,
  14. String? cachedMatchedNumber,
  15. String? phoneAccountId,
})

Query call history log entries dateFrom: unix timestamp. precision in millis. Use only one of dateFrom dateTimeFrom dateTo: unix timestamp. precision in millis. Use only one of dateTo dateTimeTo dateTimeFrom: DateTime. Same as dateFrom, but accepting DateTime. Use only one of dateFrom dateTimeFrom dateTimeTo: DateTime. Same as dateTo, but accepting DateTime. Use only one of dateTo dateTimeTo durationFrom: minimal call length in seconds durationTo: minimal call length in seconds name: call participant name (present only if in contacts) number: call participant phone number type: value from CallType enum

Implementation

static Future<Iterable<CallLogEntry>> query({
  int? dateFrom,
  int? dateTo,
  int? durationFrom,
  int? durationTo,
  DateTime? dateTimeFrom,
  DateTime? dateTimeTo,
  String? name,
  String? number,
  CallType? type,
  String? numbertype,
  String? numberlabel,
  String? cachedNumberType,
  String? cachedNumberLabel,
  String? cachedMatchedNumber,
  String? phoneAccountId,
}) async {
  assert(!(dateFrom != null && dateTimeFrom != null), 'use only one of dateTimeFrom/dateFrom');
  assert(!(dateTo != null && dateTimeTo != null), 'use only one of dateTimeTo/dateTo');

  //NOTE: Since we are accepting date params both as timestamps and DateTime objects
  // we need to determine which one to use
  int? _dateFrom = dateFrom;
  _dateFrom ??= dateTimeFrom?.millisecondsSinceEpoch;

  int? _dateTo = dateTo;
  _dateTo ??= dateTimeTo?.millisecondsSinceEpoch;

  final Map<String, String?> params = <String, String?>{
    'dateFrom': _dateFrom?.toString(),
    'dateTo': _dateTo?.toString(),
    'durationFrom': durationFrom?.toString(),
    'durationTo': durationTo?.toString(),
    'name': name,
    'number': number,
    'type': type?.index == null ? null : (type!.index + 1).toString(),
    'cachedNumberType': cachedNumberType,
    'cachedNumberLabel': cachedNumberLabel,
    'cachedMatchedNumber': cachedMatchedNumber,
    'phoneAccountId': phoneAccountId,
  };
  final Iterable<dynamic>? records = await _channel.invokeMethod('query', params);
  return records?.map((dynamic m) => CallLogEntry.fromMap(m)) ?? _EMPTY_RESULT;
}