typedTelephone property

List typedTelephone

Implementation

List<dynamic> get typedTelephone {
  List<String> telephoneTypes = [
    'TEXT',
    'TEXTPHONE',
    'VOICE',
    'VIDEO',
    'CELL',
    'PAGER',
    'FAX',
    'HOME',
    'WORK',
    'OTHER'
  ];
  List<String> telephones;
  List<String> types = [];
  List<dynamic> result = [];
  String _tel = '';

  telephones = getWordsOfPrefix("TEL");

  for (String tel in telephones) {
    try {
      if (version == "2.1" || version == "3.0") {
        _tel = RegExp(r'(?<=:).+$').firstMatch(tel)?.group(0) ?? '';
      } else if (version == "4.0") {
        _tel = RegExp(r'(?<=tel:).+$').firstMatch(tel)?.group(0) ?? '';
      }
    } catch (e) {
      _tel = '';
    }

    for (String type in telephoneTypes) {
      if (tel.toUpperCase().contains(type)) {
        types.add(type);
      }
    }

    if (_tel.isNotEmpty) {
      result.add([
        _tel,
        types,
      ]);
    }
    _tel = '';
    types = [];
  }

  return result;
}