Commit 9e9f3f3c66d661bc993f504bf36c0273d9665b58

Authored by wdn127929
1 parent 3254b134

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

@@ -41,13 +41,23 @@ class _ContantItemPageState extends State<ContantItemPage> { @@ -41,13 +41,23 @@ class _ContantItemPageState extends State<ContantItemPage> {
41 : userHistoryEntity.rname; 41 : userHistoryEntity.rname;
42 String pinyinFirst = userHistoryEntity.pinyinFirst; 42 String pinyinFirst = userHistoryEntity.pinyinFirst;
43 List<String> pinyinList = userHistoryEntity.pinyinList; 43 List<String> pinyinList = userHistoryEntity.pinyinList;
44 -  
45 - if (pinyinList.indexOf(key) != -1) {  
46 - keyTemp = name.substring(  
47 - pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);  
48 - } else if (pinyinFirst.contains(key)) { 44 + String pinyin = userHistoryEntity.pinyin;
  45 + // if (pinyinList.indexOf(key) != -1) {
  46 + // //全拼音检索一个字
  47 + // keyTemp = name.substring(
  48 + // pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);
  49 + // } else
  50 + if (pinyinFirst.contains(key)) {
49 keyTemp = name.substring( 51 keyTemp = name.substring(
50 - pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1); 52 + pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + key.length);
  53 + } else if (pinyin.indexOf(key) != -1) {
  54 + if (pinyinList.indexOf(key) != -1) {
  55 +//全拼音检索 lilao
  56 + keyTemp = name.substring(0, pinyinList.indexOf(key) + 1);
  57 + } else if (pinyinFirst.contains(key)) {
  58 + keyTemp = name.substring(
  59 + pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + key.length);
  60 + }
51 } 61 }
52 62
53 print(keyTemp); 63 print(keyTemp);
@@ -130,7 +140,7 @@ class _ContantItemPageState extends State<ContantItemPage> { @@ -130,7 +140,7 @@ class _ContantItemPageState extends State<ContantItemPage> {
130 140
131 String key = widget.model.controller.text; 141 String key = widget.model.controller.text;
132 String pinyinFirst = userHistoryEntity.pinyinFirst; 142 String pinyinFirst = userHistoryEntity.pinyinFirst;
133 - 143 + List<String> pinyinList = userHistoryEntity.pinyinList;
134 if (key == '') { 144 if (key == '') {
135 return Text(name, 145 return Text(name,
136 style: TextStyle( 146 style: TextStyle(
@@ -138,11 +148,15 @@ class _ContantItemPageState extends State<ContantItemPage> { @@ -138,11 +148,15 @@ class _ContantItemPageState extends State<ContantItemPage> {
138 } else { 148 } else {
139 return (name.contains(key) && name.length != key.length) || 149 return (name.contains(key) && name.length != key.length) ||
140 (pinyinFirst.contains(key) && pinyinFirst.length != key.length) || 150 (pinyinFirst.contains(key) && pinyinFirst.length != key.length) ||
141 - (pinyinFirst.contains(key) && pinyinFirst.length != key.length) 151 + (pinyinList.contains(key) && pinyinList.length != key.length)
142 ? _startPlaceWidget(name, key, userHistoryEntity) 152 ? _startPlaceWidget(name, key, userHistoryEntity)
143 : Text(name, 153 : Text(name,
144 style: TextStyle( 154 style: TextStyle(
145 - color: name.length == key.length 155 + color: ((name.contains(key) && name.length == key.length) ||
  156 + (pinyinFirst.contains(key) &&
  157 + pinyinFirst.length == key.length) ||
  158 + (pinyinList.contains(key) &&
  159 + pinyinList.length == key.length))
146 ? MyColours.color_199095 160 ? MyColours.color_199095
147 : MyColours.color_333333, 161 : MyColours.color_333333,
148 fontSize: ScreenUtil().setSp(32))); 162 fontSize: ScreenUtil().setSp(32)));
@@ -157,20 +171,17 @@ class _ContantItemPageState extends State<ContantItemPage> { @@ -157,20 +171,17 @@ class _ContantItemPageState extends State<ContantItemPage> {
157 : userHistoryEntity.phone; 171 : userHistoryEntity.phone;
158 172
159 String key = widget.model.controller.text; 173 String key = widget.model.controller.text;
160 - String pinyinFirst = userHistoryEntity.pinyinFirst;  
161 174
162 if (key == '') { 175 if (key == '') {
163 return Text(phone, 176 return Text(phone,
164 style: TextStyle( 177 style: TextStyle(
165 color: MyColours.color_333333, fontSize: ScreenUtil().setSp(32))); 178 color: MyColours.color_333333, fontSize: ScreenUtil().setSp(32)));
166 } else { 179 } else {
167 - return (phone.contains(key) && phone.length != key.length) ||  
168 - (pinyinFirst.contains(key) && pinyinFirst.length != key.length) ||  
169 - (pinyinFirst.contains(key) && pinyinFirst.length != key.length) 180 + return (phone.contains(key) && phone.length != key.length)
170 ? _getWidget(phone, key, fontSize: 30) 181 ? _getWidget(phone, key, fontSize: 30)
171 : Text(phone, 182 : Text(phone,
172 style: TextStyle( 183 style: TextStyle(
173 - color: phone.length == key.length 184 + color: phone.contains(key) && phone.length == key.length
174 ? MyColours.color_199095 185 ? MyColours.color_199095
175 : MyColours.color_333333, 186 : MyColours.color_333333,
176 fontSize: ScreenUtil().setSp(30))); 187 fontSize: ScreenUtil().setSp(30)));
@@ -92,17 +92,21 @@ class _ContantRightPageState extends State<ContantRightPage> { @@ -92,17 +92,21 @@ class _ContantRightPageState extends State<ContantRightPage> {
92 '', 92 '',
93 _contacts[i].displayName, 93 _contacts[i].displayName,
94 '', 94 '',
95 - _contacts[i].phones.first.value, 95 + _contacts[i].phones.first.value.replaceAll(' ', ''),
96 ''); 96 '');
97 item.pinyin = PinyinHelper.getPinyin(_contacts[i].displayName) 97 item.pinyin = PinyinHelper.getPinyin(_contacts[i].displayName)
98 .replaceAll(' ', ''); 98 .replaceAll(' ', '');
99 - item.pinyinList = 99 + List<String> pinyinList =
100 PinyinHelper.getPinyin(_contacts[i].displayName).split(' '); 100 PinyinHelper.getPinyin(_contacts[i].displayName).split(' ');
101 item.pinyinFirst = ''; 101 item.pinyinFirst = '';
102 - for (int j = 0; j < item.pinyinList.length; j++) {  
103 - String letter = item.pinyinList[j]; 102 + item.pinyinList = [];
  103 + String pinyinAll = ''; //组装全拼组合
  104 + for (int j = 0; j < pinyinList.length; j++) {
  105 + String letter = pinyinList[j];
  106 + pinyinAll += pinyinList[j];
  107 + item.pinyinList.add(pinyinAll);
104 if (letter.length > 0) { 108 if (letter.length > 0) {
105 - item.pinyinFirst += item.pinyinList[j].substring(0, 1); 109 + item.pinyinFirst += pinyinList[j].substring(0, 1);
106 } else { 110 } else {
107 item.pinyinFirst += ''; 111 item.pinyinFirst += '';
108 } 112 }
@@ -50,12 +50,17 @@ class ContantShowModel extends ChangeNotifier { @@ -50,12 +50,17 @@ class ContantShowModel extends ChangeNotifier {
50 for (int i = 0; i < userHistorys.length; i++) { 50 for (int i = 0; i < userHistorys.length; i++) {
51 UserHistoryEntity item = userHistorys[i]; 51 UserHistoryEntity item = userHistorys[i];
52 item.pinyin = PinyinHelper.getPinyin(item.rname).replaceAll(' ', ''); 52 item.pinyin = PinyinHelper.getPinyin(item.rname).replaceAll(' ', '');
53 - item.pinyinList = PinyinHelper.getPinyin(item.rname).split(' '); 53 + List<String> pinyinList =
  54 + PinyinHelper.getPinyin(item.rname).split(' ');
54 item.pinyinFirst = ''; 55 item.pinyinFirst = '';
55 - for (int j = 0; j < item.pinyinList.length; j++) {  
56 - String letter = item.pinyinList[j]; 56 + item.pinyinList = [];
  57 + String pinyinAll = ''; //组装全拼组合
  58 + for (int j = 0; j < pinyinList.length; j++) {
  59 + String letter = pinyinList[j];
  60 + pinyinAll += pinyinList[j];
  61 + item.pinyinList.add(pinyinAll);
57 if (letter.length > 0) { 62 if (letter.length > 0) {
58 - item.pinyinFirst += item.pinyinList[j].substring(0, 1); 63 + item.pinyinFirst += pinyinList[j].substring(0, 1);
59 } else { 64 } else {
60 item.pinyinFirst += ''; 65 item.pinyinFirst += '';
61 } 66 }
@@ -81,8 +86,9 @@ class ContantShowModel extends ChangeNotifier { @@ -81,8 +86,9 @@ class ContantShowModel extends ChangeNotifier {
81 for (int i = 0; i < userHistorys.length; i++) { 86 for (int i = 0; i < userHistorys.length; i++) {
82 String name = userHistorys[i].rname; 87 String name = userHistorys[i].rname;
83 String pinyinFirst = userHistorys[i].pinyinFirst; 88 String pinyinFirst = userHistorys[i].pinyinFirst;
84 - List<String> pinyinList = userHistorys[i].pinyinList; 89 + // String pinyin = userHistorys[i].pinyin;
85 String phone = userHistorys[i].phone; 90 String phone = userHistorys[i].phone;
  91 + List<String> pinyinList = userHistorys[i].pinyinList;
86 if (name.contains(key) || 92 if (name.contains(key) ||
87 pinyinFirst.contains(key) || 93 pinyinFirst.contains(key) ||
88 phone.contains(key) || 94 phone.contains(key) ||
@@ -94,6 +100,7 @@ class ContantShowModel extends ChangeNotifier { @@ -94,6 +100,7 @@ class ContantShowModel extends ChangeNotifier {
94 String name = contacts[i].rname; 100 String name = contacts[i].rname;
95 String pinyinFirst = contacts[i].pinyinFirst; 101 String pinyinFirst = contacts[i].pinyinFirst;
96 List<String> pinyinList = contacts[i].pinyinList; 102 List<String> pinyinList = contacts[i].pinyinList;
  103 + // String pinyin = contacts[i].pinyin;
97 String phone = contacts[i].phone; 104 String phone = contacts[i].phone;
98 if (name.contains(key) || 105 if (name.contains(key) ||
99 pinyinFirst.contains(key) || 106 pinyinFirst.contains(key) ||