Commit 9e9f3f3c66d661bc993f504bf36c0273d9665b58

Authored by wdn127929
1 parent 3254b134

联系人搜索,支持姓名汉字、全拼音、手机号、姓氏开头

... ... @@ -41,13 +41,23 @@ class _ContantItemPageState extends State<ContantItemPage> {
: userHistoryEntity.rname;
String pinyinFirst = userHistoryEntity.pinyinFirst;
List<String> pinyinList = userHistoryEntity.pinyinList;
if (pinyinList.indexOf(key) != -1) {
keyTemp = name.substring(
pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);
} else if (pinyinFirst.contains(key)) {
String pinyin = userHistoryEntity.pinyin;
// if (pinyinList.indexOf(key) != -1) {
// //全拼音检索一个字
// keyTemp = name.substring(
// pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);
// } else
if (pinyinFirst.contains(key)) {
keyTemp = name.substring(
pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1);
pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + key.length);
} else if (pinyin.indexOf(key) != -1) {
if (pinyinList.indexOf(key) != -1) {
//全拼音检索 lilao
keyTemp = name.substring(0, pinyinList.indexOf(key) + 1);
} else if (pinyinFirst.contains(key)) {
keyTemp = name.substring(
pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + key.length);
}
}
print(keyTemp);
... ... @@ -130,7 +140,7 @@ class _ContantItemPageState extends State<ContantItemPage> {
String key = widget.model.controller.text;
String pinyinFirst = userHistoryEntity.pinyinFirst;
List<String> pinyinList = userHistoryEntity.pinyinList;
if (key == '') {
return Text(name,
style: TextStyle(
... ... @@ -138,11 +148,15 @@ class _ContantItemPageState extends State<ContantItemPage> {
} else {
return (name.contains(key) && name.length != key.length) ||
(pinyinFirst.contains(key) && pinyinFirst.length != key.length) ||
(pinyinFirst.contains(key) && pinyinFirst.length != key.length)
(pinyinList.contains(key) && pinyinList.length != key.length)
? _startPlaceWidget(name, key, userHistoryEntity)
: Text(name,
style: TextStyle(
color: name.length == key.length
color: ((name.contains(key) && name.length == key.length) ||
(pinyinFirst.contains(key) &&
pinyinFirst.length == key.length) ||
(pinyinList.contains(key) &&
pinyinList.length == key.length))
? MyColours.color_199095
: MyColours.color_333333,
fontSize: ScreenUtil().setSp(32)));
... ... @@ -157,20 +171,17 @@ class _ContantItemPageState extends State<ContantItemPage> {
: userHistoryEntity.phone;
String key = widget.model.controller.text;
String pinyinFirst = userHistoryEntity.pinyinFirst;
if (key == '') {
return Text(phone,
style: TextStyle(
color: MyColours.color_333333, fontSize: ScreenUtil().setSp(32)));
} else {
return (phone.contains(key) && phone.length != key.length) ||
(pinyinFirst.contains(key) && pinyinFirst.length != key.length) ||
(pinyinFirst.contains(key) && pinyinFirst.length != key.length)
return (phone.contains(key) && phone.length != key.length)
? _getWidget(phone, key, fontSize: 30)
: Text(phone,
style: TextStyle(
color: phone.length == key.length
color: phone.contains(key) && phone.length == key.length
? MyColours.color_199095
: MyColours.color_333333,
fontSize: ScreenUtil().setSp(30)));
... ...
... ... @@ -92,17 +92,21 @@ class _ContantRightPageState extends State<ContantRightPage> {
'',
_contacts[i].displayName,
'',
_contacts[i].phones.first.value,
_contacts[i].phones.first.value.replaceAll(' ', ''),
'');
item.pinyin = PinyinHelper.getPinyin(_contacts[i].displayName)
.replaceAll(' ', '');
item.pinyinList =
List<String> pinyinList =
PinyinHelper.getPinyin(_contacts[i].displayName).split(' ');
item.pinyinFirst = '';
for (int j = 0; j < item.pinyinList.length; j++) {
String letter = item.pinyinList[j];
item.pinyinList = [];
String pinyinAll = ''; //组装全拼组合
for (int j = 0; j < pinyinList.length; j++) {
String letter = pinyinList[j];
pinyinAll += pinyinList[j];
item.pinyinList.add(pinyinAll);
if (letter.length > 0) {
item.pinyinFirst += item.pinyinList[j].substring(0, 1);
item.pinyinFirst += pinyinList[j].substring(0, 1);
} else {
item.pinyinFirst += '';
}
... ...
... ... @@ -50,12 +50,17 @@ class ContantShowModel extends ChangeNotifier {
for (int i = 0; i < userHistorys.length; i++) {
UserHistoryEntity item = userHistorys[i];
item.pinyin = PinyinHelper.getPinyin(item.rname).replaceAll(' ', '');
item.pinyinList = PinyinHelper.getPinyin(item.rname).split(' ');
List<String> pinyinList =
PinyinHelper.getPinyin(item.rname).split(' ');
item.pinyinFirst = '';
for (int j = 0; j < item.pinyinList.length; j++) {
String letter = item.pinyinList[j];
item.pinyinList = [];
String pinyinAll = ''; //组装全拼组合
for (int j = 0; j < pinyinList.length; j++) {
String letter = pinyinList[j];
pinyinAll += pinyinList[j];
item.pinyinList.add(pinyinAll);
if (letter.length > 0) {
item.pinyinFirst += item.pinyinList[j].substring(0, 1);
item.pinyinFirst += pinyinList[j].substring(0, 1);
} else {
item.pinyinFirst += '';
}
... ... @@ -81,8 +86,9 @@ class ContantShowModel extends ChangeNotifier {
for (int i = 0; i < userHistorys.length; i++) {
String name = userHistorys[i].rname;
String pinyinFirst = userHistorys[i].pinyinFirst;
List<String> pinyinList = userHistorys[i].pinyinList;
// String pinyin = userHistorys[i].pinyin;
String phone = userHistorys[i].phone;
List<String> pinyinList = userHistorys[i].pinyinList;
if (name.contains(key) ||
pinyinFirst.contains(key) ||
phone.contains(key) ||
... ... @@ -94,6 +100,7 @@ class ContantShowModel extends ChangeNotifier {
String name = contacts[i].rname;
String pinyinFirst = contacts[i].pinyinFirst;
List<String> pinyinList = contacts[i].pinyinList;
// String pinyin = contacts[i].pinyin;
String phone = contacts[i].phone;
if (name.contains(key) ||
pinyinFirst.contains(key) ||
... ...