【问题标题】:How to get contact number from contact_service Flutter如何从contact_service Flutter获取联系电话
【发布时间】:2020-12-12 05:44:39
【问题描述】:

我正在使用contact_service 来管理我的联系人。我已将所有联系人作为列表获取。我想使用每个联系人的电话号码访问字段。我想将其作为字符串获取,但 Contact 类中的属性是

Iterable<Item> phones

你知道我怎样才能得到电话号码吗? 链接到这个包: https://pub.dev/packages/contacts_service 提前致谢

【问题讨论】:

    标签: flutter package


    【解决方案1】:

    对于每个Iterable&lt;Item&gt; phonesItem.value 返回电话号码字符串。

    List<String> names = [];
    List<String> phones = [];
    
    Iterable<Contact> _contacts = await ContactsService.getContacts(withThumbnails: false);
    
    _contacts.forEach((contact) {
      contact.phones.toSet().forEach((phone) {
        names.add(contact.displayName ?? contact.givenName);
        phones.add(phone.value);
      });
    });
    

    【讨论】:

      【解决方案2】:
        List<Contact> _contacts;
      
      
           Future<void> refreshContacts() async {
              // Load without thumbnails initially.
              var contacts = (await ContactsService.getContacts(
                      withThumbnails: false, iOSLocalizedLabels: iOSLocalizedLabels))
                  .toList();
              setState(() {
                _contacts = contacts;
              });
            }
      

      并使用此联系人列表在ListView/Column 中呈现小部件

      在此处遵循完整的示例 https://github.com/lukasgit/flutter_contacts/blob/master/example/lib/contacts_list_page.dart

      【讨论】:

      • 感谢您的宝贵时间,但您错过了我的问题。我已经问过如何访问电话号码。我已经获取联系人列表。但我不知道如何访问每个联系人的电话号码
      猜你喜欢
      • 2016-12-12
      • 1970-01-01
      • 2015-12-16
      • 1970-01-01
      • 2015-01-24
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      相关资源
      最近更新 更多