//通讯录按照字母分类,通常才手机app中设置通讯录需要按照字符分组联系人,可使用如下方法
Map sortMap = <String, List>{};
if (res['data'] is List) {
List d = res['data'];
// a - z
for (var i = 97; i < 123; i++) {
String key = String.fromCharCode(i);
// key.codeUnits
sortMap[key] = [];
}
// # 未分类
sortMap['#'] = [];
for (var e in d) {
String key = PinyinHelper.getShortPinyin(e['name'].toString());
if (key.isEmpty) continue;
key = key.substring(0, 1);
if (sortMap.containsKey(key)) {
if (sortMap[key] is List) {
(sortMap[key] as List).add(e);
}
} else {
sortMap['#'].add(e);
}
}
setState(() => null);
//根据电话号码去重
final phones = value.map((e) => e["phone"]).toSet();
value.retainWhere((x) => phones.remove(x['phone']));
//拨打电话
ListTile(
contentPadding: EdgeInsets.all(0),
leading: CircleAvatar(
radius: 42.w,
backgroundColor: Colors.brown,
backgroundImage: NetworkImage(null ?? ''),
),
title: UIText(val['name']),
onTap: () {
launch("tel:" + val['phone']);
},
),
QQ技术交流群:707 196 135 (大前端技术交流群)