Commit 3254b13471d9f96520691fbaac8d8bac4c888e08

Authored by wdn127929
1 parent daa1e206

搜索联系人

  1 +import 'package:flutter/material.dart';
  2 +import 'package:flutter_screenutil/screenutil.dart';
  3 +import 'package:one_key/models/user_history_entity.dart';
  4 +import 'package:one_key/provider/contant_show_model.dart';
  5 +import 'package:one_key/res/colors.dart';
  6 +import 'package:one_key/utils/utils.dart';
  7 +import 'package:one_key/widgets/MyDivider.dart';
  8 +import 'package:one_key/widgets/v_empty_view.dart';
  9 +
  10 +class ContantItemPage extends StatefulWidget {
  11 + final int index;
  12 + final ContantShowModel model;
  13 + final GestureTapCallback onTap;
  14 + final List<UserHistoryEntity> data;
  15 + ContantItemPage({Key key, this.index, this.model, this.onTap, this.data})
  16 + : super(key: key);
  17 +
  18 + @override
  19 + _ContantItemPageState createState() => _ContantItemPageState();
  20 +}
  21 +
  22 +class _ContantItemPageState extends State<ContantItemPage> {
  23 + _getWidget(String title, String key, {fontSize = 32}) {
  24 + return RichText(
  25 + text: TextSpan(
  26 + children: getTextSpanList(title,
  27 + searchContent: key, fontSize: fontSize)));
  28 + }
  29 +
  30 + ///关键字在前面布局
  31 + _startPlaceWidget(
  32 + String title, String key, UserHistoryEntity userHistoryEntity,
  33 + {fontSize = 32}) {
  34 + String keyTemp = '';
  35 + if (Utils.isChinese(key)) {
  36 + keyTemp = key;
  37 + } else {
  38 + String name =
  39 + userHistoryEntity.rname == null || userHistoryEntity.rname == ''
  40 + ? ''
  41 + : userHistoryEntity.rname;
  42 + String pinyinFirst = userHistoryEntity.pinyinFirst;
  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)) {
  49 + keyTemp = name.substring(
  50 + pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1);
  51 + }
  52 +
  53 + print(keyTemp);
  54 + }
  55 + return _getWidget(title, keyTemp, fontSize: fontSize);
  56 + }
  57 +
  58 + List<TextSpan> getTextSpanList(String textContent,
  59 + {String searchContent = '',
  60 + String frontContent = '',
  61 + int fontSize = 32,
  62 + Color fontColor = MyColours.color_333333,
  63 + Color selectFontColor = MyColours.color_199095}) {
  64 + List<TextSpan> textSpanList = [];
  65 +
  66 + if (frontContent.isEmpty == false) {
  67 + textSpanList.add(TextSpan(
  68 + text: frontContent,
  69 + style: TextStyle(
  70 + fontSize: ScreenUtil().setSp(fontSize), color: fontColor)));
  71 + }
  72 +
  73 + ///搜索内容不为空并且 显示内容中存在与搜索内容相同的文字
  74 + if (searchContent != null &&
  75 + searchContent.isEmpty == false &&
  76 + textContent.contains(searchContent)) {
  77 + List<Map> _strMapList = [];
  78 + bool _isContains = true;
  79 + while (_isContains) {
  80 + int startIndex = textContent.indexOf(searchContent);
  81 + String showStr = textContent.substring(
  82 + startIndex, startIndex + searchContent.length);
  83 + Map _strMap;
  84 + if (startIndex > 0) {
  85 + String normalStr = textContent.substring(0, startIndex);
  86 + _strMap = Map();
  87 + _strMap['content'] = normalStr;
  88 + _strMap['isHighlight'] = false;
  89 + _strMapList.add(_strMap);
  90 + }
  91 + _strMap = Map();
  92 + _strMap['content'] = showStr;
  93 + _strMap['isHighlight'] = true;
  94 + _strMapList.add(_strMap);
  95 + textContent = textContent.substring(
  96 + startIndex + searchContent.length, textContent.length);
  97 +
  98 + _isContains = textContent.contains(searchContent);
  99 + if (!_isContains && textContent != '') {
  100 + _strMap = Map();
  101 + _strMap['content'] = textContent;
  102 + _strMap['isHighlight'] = false;
  103 + _strMapList.add(_strMap);
  104 + }
  105 + }
  106 + _strMapList.forEach((map) {
  107 + textSpanList.add(TextSpan(
  108 + text: map['content'],
  109 + style: TextStyle(
  110 + fontSize: ScreenUtil().setSp(fontSize),
  111 + color: map['isHighlight'] ? selectFontColor : fontColor)));
  112 + });
  113 + } else {
  114 + ///正常显示所有文字
  115 + textSpanList.add(TextSpan(
  116 + text: textContent,
  117 + style:
  118 + TextStyle(fontSize: ScreenUtil().setSp(fontSize), color: fontColor),
  119 + ));
  120 + }
  121 + return textSpanList;
  122 + }
  123 +
  124 + ///姓名widget
  125 + Widget _getNameWidget(UserHistoryEntity userHistoryEntity) {
  126 + String name =
  127 + userHistoryEntity.rname == null || userHistoryEntity.rname == ''
  128 + ? ''
  129 + : userHistoryEntity.rname;
  130 +
  131 + String key = widget.model.controller.text;
  132 + String pinyinFirst = userHistoryEntity.pinyinFirst;
  133 +
  134 + if (key == '') {
  135 + return Text(name,
  136 + style: TextStyle(
  137 + color: MyColours.color_333333, fontSize: ScreenUtil().setSp(32)));
  138 + } else {
  139 + return (name.contains(key) && name.length != key.length) ||
  140 + (pinyinFirst.contains(key) && pinyinFirst.length != key.length) ||
  141 + (pinyinFirst.contains(key) && pinyinFirst.length != key.length)
  142 + ? _startPlaceWidget(name, key, userHistoryEntity)
  143 + : Text(name,
  144 + style: TextStyle(
  145 + color: name.length == key.length
  146 + ? MyColours.color_199095
  147 + : MyColours.color_333333,
  148 + fontSize: ScreenUtil().setSp(32)));
  149 + }
  150 + }
  151 +
  152 + ///电话widget
  153 + Widget _getPhoneWidget(UserHistoryEntity userHistoryEntity) {
  154 + String phone =
  155 + userHistoryEntity.phone == null || userHistoryEntity.phone == ''
  156 + ? ''
  157 + : userHistoryEntity.phone;
  158 +
  159 + String key = widget.model.controller.text;
  160 + String pinyinFirst = userHistoryEntity.pinyinFirst;
  161 +
  162 + if (key == '') {
  163 + return Text(phone,
  164 + style: TextStyle(
  165 + color: MyColours.color_333333, fontSize: ScreenUtil().setSp(32)));
  166 + } 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)
  170 + ? _getWidget(phone, key, fontSize: 30)
  171 + : Text(phone,
  172 + style: TextStyle(
  173 + color: phone.length == key.length
  174 + ? MyColours.color_199095
  175 + : MyColours.color_333333,
  176 + fontSize: ScreenUtil().setSp(30)));
  177 + }
  178 + }
  179 +
  180 + @override
  181 + Widget build(BuildContext context) {
  182 + return InkWell(
  183 + onTap: widget.onTap,
  184 + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
  185 + widget.index == 0
  186 + ? MyDivider(
  187 + double.infinity,
  188 + ScreenUtil().setWidth(20),
  189 + color: MyColours.color_f5f5f5,
  190 + )
  191 + : Container(),
  192 + Container(
  193 + width: double.infinity,
  194 + padding: EdgeInsets.symmetric(
  195 + horizontal: ScreenUtil().setWidth(40),
  196 + vertical: ScreenUtil().setWidth(30)),
  197 + height: ScreenUtil().setWidth(76 * 2),
  198 + decoration: BoxDecoration(
  199 + border: Border(
  200 + top: widget.index == 0
  201 + ? BorderSide(
  202 + width: ScreenUtil().setWidth(2),
  203 + color: MyColours.color_E0E0E0)
  204 + : BorderSide(width: 0, color: Colors.transparent),
  205 + bottom: BorderSide(
  206 + width: ScreenUtil().setWidth(2),
  207 + color: MyColours.color_E0E0E0))),
  208 + child: Column(
  209 + crossAxisAlignment: CrossAxisAlignment.start,
  210 + children: [
  211 + _getNameWidget(widget.data[widget.index]),
  212 + VEmptyView(10),
  213 + _getPhoneWidget(widget.data[widget.index])
  214 + ],
  215 + ),
  216 + )
  217 + ]));
  218 + }
  219 +}
1 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
2 import 'package:flutter_easyrefresh/easy_refresh.dart'; 2 import 'package:flutter_easyrefresh/easy_refresh.dart';
3 -import 'package:flutter_screenutil/flutter_screenutil.dart'; 3 +
4 import 'package:one_key/constant/state.dart'; 4 import 'package:one_key/constant/state.dart';
5 -import 'package:one_key/models/user_history_entity.dart'; 5 +
  6 +import 'package:one_key/pages/my/contant_item_page.dart';
6 import 'package:one_key/provider/contant_show_model.dart'; 7 import 'package:one_key/provider/contant_show_model.dart';
7 import 'package:one_key/provider/user_model.dart'; 8 import 'package:one_key/provider/user_model.dart';
8 -import 'package:one_key/res/colors.dart';  
9 import 'package:one_key/utils/dialog_util.dart'; 9 import 'package:one_key/utils/dialog_util.dart';
10 -import 'package:one_key/utils/utils.dart';  
11 -import 'package:one_key/widgets/MyDivider.dart';  
12 10
13 import 'package:one_key/widgets/page_exception.dart'; 11 import 'package:one_key/widgets/page_exception.dart';
14 -import 'package:one_key/widgets/v_empty_view.dart'; 12 +
15 import 'package:provider/provider.dart'; 13 import 'package:provider/provider.dart';
16 14
17 class ContantLeftPage extends StatefulWidget { 15 class ContantLeftPage extends StatefulWidget {
@@ -42,344 +40,6 @@ class _ContantLeftPageState extends State<ContantLeftPage> { @@ -42,344 +40,6 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
42 await contantShowModel.getUserHistorys(context, params); 40 await contantShowModel.getUserHistorys(context, params);
43 } 41 }
44 42
45 - _getWidget(String title, String key) {  
46 - return RichText(  
47 - text: TextSpan(children: getTextSpanList(title, searchContent: key)));  
48 - }  
49 -  
50 - ///关键字在前面布局  
51 - _startPlaceWidget(  
52 - String title, String key, UserHistoryEntity userHistoryEntity) {  
53 - String keyTemp = '';  
54 - if (Utils.isChinese(key)) {  
55 - keyTemp = key;  
56 - } else {  
57 - String name =  
58 - userHistoryEntity.rname == null || userHistoryEntity.rname == ''  
59 - ? ''  
60 - : userHistoryEntity.rname;  
61 - String pinyinFirst = userHistoryEntity.pinyinFirst;  
62 - List<String> pinyinList = userHistoryEntity.pinyinList;  
63 -  
64 - if (pinyinList.indexOf(key) != -1) {  
65 - keyTemp = name.substring(  
66 - pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);  
67 - } else if (pinyinFirst.contains(key)) {  
68 - keyTemp = name.substring(  
69 - pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1);  
70 - }  
71 -  
72 - print(keyTemp);  
73 - }  
74 - return _getWidget(title, keyTemp);  
75 - // return RichText(  
76 - // maxLines: 1,  
77 - // overflow: TextOverflow.ellipsis,  
78 - // text: TextSpan(  
79 - // children: [  
80 - // TextSpan(  
81 - // text: keyTemp,  
82 - // style: TextStyle(  
83 - // fontSize: ScreenUtil().setSp(32),  
84 - // color: MyColours.color_199095),  
85 - // ),  
86 - // TextSpan(  
87 - // text: title.replaceAll(keyTemp, ''),  
88 - // style: TextStyle(  
89 - // fontSize: ScreenUtil().setSp(32),  
90 - // color: MyColours.color_333333),  
91 - // ),  
92 - // ],  
93 - // ));  
94 - }  
95 -  
96 - // ///关键字在后面布局  
97 - // _endlaceWidget(  
98 - // String title, String key, UserHistoryEntity userHistoryEntity) {  
99 - // String keyTemp = '';  
100 - // if (Utils.isChinese(key)) {  
101 - // keyTemp = key;  
102 - // } else if (Utils.isPinyin(key)) {  
103 - // String name =  
104 - // userHistoryEntity.rname == null || userHistoryEntity.rname == ''  
105 - // ? ''  
106 - // : userHistoryEntity.rname;  
107 - // String pinyinFirst = userHistoryEntity.pinyinFirst;  
108 - // List<String> pinyinList = userHistoryEntity.pinyinList;  
109 - // String pinyin = userHistoryEntity.pinyin;  
110 - // if (pinyinList.indexOf(key) != -1) {  
111 - // keyTemp = name.substring(  
112 - // pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);  
113 - // } else if (pinyinFirst.contains(key)) {  
114 - // keyTemp = name.substring(  
115 - // pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1);  
116 - // }  
117 - // print(keyTemp);  
118 - // }  
119 - // return RichText(  
120 - // maxLines: 1,  
121 - // overflow: TextOverflow.ellipsis,  
122 - // text: TextSpan(  
123 - // children: [  
124 - // TextSpan(  
125 - // text: title.replaceAll(keyTemp, ''),  
126 - // style: TextStyle(  
127 - // fontSize: ScreenUtil().setSp(32),  
128 - // color: MyColours.color_333333),  
129 - // ),  
130 - // TextSpan(  
131 - // text: keyTemp,  
132 - // style: TextStyle(  
133 - // fontSize: ScreenUtil().setSp(32),  
134 - // color: MyColours.color_199095),  
135 - // ),  
136 - // ],  
137 - // ));  
138 - // }  
139 -  
140 - // ///关键字在中间布局  
141 - // _middlePlaceWidget(  
142 - // String title, String key, UserHistoryEntity userHistoryEntity) {  
143 - // String keyTemp = '';  
144 - // if (Utils.isChinese(key)) {  
145 - // keyTemp = key;  
146 - // } else if (Utils.isPinyin(key)) {  
147 - // String name =  
148 - // userHistoryEntity.rname == null || userHistoryEntity.rname == ''  
149 - // ? ''  
150 - // : userHistoryEntity.rname;  
151 - // String pinyinFirst = userHistoryEntity.pinyinFirst;  
152 - // List<String> pinyinList = userHistoryEntity.pinyinList;  
153 - // String pinyin = userHistoryEntity.pinyin;  
154 - // if (pinyinFirst.contains(key)) {  
155 - // keyTemp = name.substring(  
156 - // pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1);  
157 - // } else if (pinyinList.indexOf(key) != -1) {  
158 - // keyTemp = name.substring(  
159 - // pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);  
160 - // }  
161 - // print(keyTemp);  
162 - // }  
163 - // return RichText(  
164 - // maxLines: 1,  
165 - // overflow: TextOverflow.ellipsis,  
166 - // text: TextSpan(  
167 - // children: [  
168 - // TextSpan(  
169 - // text: title.substring(0, title.indexOf(keyTemp)),  
170 - // style: TextStyle(  
171 - // fontSize: ScreenUtil().setSp(32),  
172 - // color: MyColours.color_333333),  
173 - // ),  
174 - // TextSpan(  
175 - // text: keyTemp,  
176 - // style: TextStyle(  
177 - // fontSize: ScreenUtil().setSp(32),  
178 - // color: MyColours.color_199095),  
179 - // ),  
180 - // TextSpan(  
181 - // text: title.substring(  
182 - // title.lastIndexOf(keyTemp) + keyTemp.length, title.length),  
183 - // style: TextStyle(  
184 - // fontSize: ScreenUtil().setSp(32),  
185 - // color: MyColours.color_333333)),  
186 - // ],  
187 - // ),  
188 - // );  
189 - // }  
190 -  
191 - List<TextSpan> getTextSpanList(String textContent,  
192 - {String searchContent = '',  
193 - String frontContent = '',  
194 - int fontSize = 32,  
195 - Color fontColor = MyColours.color_333333,  
196 - Color selectFontColor = MyColours.color_199095}) {  
197 - List<TextSpan> textSpanList = [];  
198 -  
199 - if (frontContent.isEmpty == false) {  
200 - textSpanList.add(TextSpan(  
201 - text: frontContent,  
202 - style: TextStyle(  
203 - fontSize: ScreenUtil().setSp(fontSize), color: fontColor)));  
204 - }  
205 -  
206 - ///搜索内容不为空并且 显示内容中存在与搜索内容相同的文字  
207 - if (searchContent != null &&  
208 - searchContent.isEmpty == false &&  
209 - textContent.contains(searchContent)) {  
210 - List<Map> _strMapList = [];  
211 - bool _isContains = true;  
212 - while (_isContains) {  
213 - int startIndex = textContent.indexOf(searchContent);  
214 - String showStr = textContent.substring(  
215 - startIndex, startIndex + searchContent.length);  
216 - Map _strMap;  
217 - if (startIndex > 0) {  
218 - String normalStr = textContent.substring(0, startIndex);  
219 - _strMap = Map();  
220 - _strMap['content'] = normalStr;  
221 - _strMap['isHighlight'] = false;  
222 - _strMapList.add(_strMap);  
223 - }  
224 - _strMap = Map();  
225 - _strMap['content'] = showStr;  
226 - _strMap['isHighlight'] = true;  
227 - _strMapList.add(_strMap);  
228 - textContent = textContent.substring(  
229 - startIndex + searchContent.length, textContent.length);  
230 -  
231 - _isContains = textContent.contains(searchContent);  
232 - if (!_isContains && textContent != '') {  
233 - _strMap = Map();  
234 - _strMap['content'] = textContent;  
235 - _strMap['isHighlight'] = false;  
236 - _strMapList.add(_strMap);  
237 - }  
238 - }  
239 - _strMapList.forEach((map) {  
240 - textSpanList.add(TextSpan(  
241 - text: map['content'],  
242 - style: TextStyle(  
243 - fontSize: ScreenUtil().setSp(fontSize),  
244 - color: map['isHighlight'] ? selectFontColor : fontColor)));  
245 - });  
246 - } else {  
247 - ///正常显示所有文字  
248 - textSpanList.add(TextSpan(  
249 - text: textContent,  
250 - style:  
251 - TextStyle(fontSize: ScreenUtil().setSp(fontSize), color: fontColor),  
252 - ));  
253 - }  
254 - return textSpanList;  
255 - }  
256 -  
257 - Widget _getNameWidget(UserHistoryEntity userHistoryEntity) {  
258 - String name =  
259 - userHistoryEntity.rname == null || userHistoryEntity.rname == ''  
260 - ? ''  
261 - : userHistoryEntity.rname;  
262 - // String phone =  
263 - // userHistoryEntity.phone == null || userHistoryEntity.phone == ''  
264 - // ? ''  
265 - // : userHistoryEntity.phone;  
266 - String key = contantShowModel.controller.text;  
267 - String pinyinFirst = userHistoryEntity.pinyinFirst;  
268 - List<String> pinyinList = userHistoryEntity.pinyinList;  
269 - String pinyin = userHistoryEntity.pinyin;  
270 - if (key == '') {  
271 - return Text(name,  
272 - style: TextStyle(  
273 - color: MyColours.color_333333, fontSize: ScreenUtil().setSp(32)));  
274 - } else {  
275 - if (Utils.isChinese(key) || Utils.isNum(key)) {  
276 - return name.contains(key) && name.length != key.length  
277 - ? _startPlaceWidget(name, key, userHistoryEntity)  
278 - : Text(name,  
279 - style: TextStyle(  
280 - color: name.length == key.length  
281 - ? MyColours.color_199095  
282 - : MyColours.color_333333,  
283 - fontSize: ScreenUtil().setSp(32)));  
284 - } else if (Utils.isPinyin(key)) {  
285 - if (!pinyinFirst.contains(key) && !pinyinList.contains(key)) {  
286 - return Text(name,  
287 - style: TextStyle(  
288 - color: MyColours.color_333333,  
289 - fontSize: ScreenUtil().setSp(32)));  
290 - } else {  
291 - if (pinyinFirst.contains(key)) {  
292 - return pinyinFirst.contains(key) && pinyinFirst.length != key.length  
293 - ? Row(  
294 - children: <Widget>[  
295 - pinyinFirst.startsWith(key)  
296 - ? _startPlaceWidget(name, key, userHistoryEntity)  
297 - : Text(''),  
298 - (pinyinFirst.length != key.length &&  
299 - pinyinFirst.endsWith(key))  
300 - ? _startPlaceWidget(name, key, userHistoryEntity)  
301 - : Text(''),  
302 - (!pinyinFirst.endsWith(key) &&  
303 - !pinyinFirst.startsWith(key))  
304 - ? _startPlaceWidget(name, key, userHistoryEntity)  
305 - : Text('')  
306 - ],  
307 - )  
308 - : Text(name,  
309 - style: TextStyle(  
310 - color: pinyinFirst.length == key.length  
311 - ? MyColours.color_199095  
312 - : MyColours.color_333333,  
313 - fontSize: ScreenUtil().setSp(32)));  
314 - } else if (pinyinList.contains(key)) {  
315 - return pinyinList.contains(key) && pinyin.length != key.length  
316 - ? Row(  
317 - children: <Widget>[  
318 - pinyin.startsWith(key)  
319 - ? _startPlaceWidget(name, key, userHistoryEntity)  
320 - : Text(''),  
321 - pinyin.endsWith(key)  
322 - ? _startPlaceWidget(name, key, userHistoryEntity)  
323 - : Text(''),  
324 - (!pinyin.endsWith(key) && !pinyin.startsWith(key))  
325 - ? _startPlaceWidget(name, key, userHistoryEntity)  
326 - : Text('')  
327 - ],  
328 - )  
329 - : Text(name,  
330 - style: TextStyle(  
331 - color: MyColours.color_333333,  
332 - fontSize: ScreenUtil().setSp(32)));  
333 - }  
334 - }  
335 - } else {  
336 - return Text(name,  
337 - style: TextStyle(  
338 - color: MyColours.color_333333,  
339 - fontSize: ScreenUtil().setSp(32)));  
340 - }  
341 - }  
342 - }  
343 -  
344 - Widget _getPhoneWidget(UserHistoryEntity userHistoryEntity) {  
345 - String phone =  
346 - userHistoryEntity.phone == null || userHistoryEntity.phone == ''  
347 - ? ''  
348 - : userHistoryEntity.phone;  
349 - String key = contantShowModel.controller.text;  
350 - String pinyinFirst = userHistoryEntity.pinyinFirst;  
351 - List<String> pinyinList = userHistoryEntity.pinyinList;  
352 - String pinyin = userHistoryEntity.pinyin;  
353 - if (key == '') {  
354 - return Text(phone,  
355 - style: TextStyle(  
356 - color: MyColours.color_999999, fontSize: ScreenUtil().setSp(30)));  
357 - } else {  
358 - if (Utils.isNum(key)) {  
359 - return phone.contains(key) && phone.length != key.length  
360 - ? Row(  
361 - children: <Widget>[  
362 - phone.startsWith(key) ||  
363 - pinyinFirst.startsWith(key) ||  
364 - pinyinList[0] == key  
365 - ? _startPlaceWidget(phone, key, userHistoryEntity)  
366 - : Text(''),  
367 - (phone.length != key.length && phone.endsWith(key))  
368 - ? _startPlaceWidget(phone, key, userHistoryEntity)  
369 - : Text(''),  
370 - (!phone.endsWith(key) && !phone.startsWith(key))  
371 - ? _startPlaceWidget(phone, key, userHistoryEntity)  
372 - : Text('')  
373 - ],  
374 - )  
375 - : Text(phone,  
376 - style: TextStyle(  
377 - color: MyColours.color_999999,  
378 - fontSize: ScreenUtil().setSp(30)));  
379 - }  
380 - }  
381 - }  
382 -  
383 @override 43 @override
384 Widget build(BuildContext context) { 44 Widget build(BuildContext context) {
385 contantShowModel = Provider.of<ContantShowModel>(context, listen: true); 45 contantShowModel = Provider.of<ContantShowModel>(context, listen: true);
@@ -389,8 +49,6 @@ class _ContantLeftPageState extends State<ContantLeftPage> { @@ -389,8 +49,6 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
389 return ExceptionPage( 49 return ExceptionPage(
390 pageState: model.pageStateLeft, 50 pageState: model.pageStateLeft,
391 callback: () { 51 callback: () {
392 - // offset = 0;  
393 - // getMessages();  
394 model.pageStateLeft = PageState.Loading; 52 model.pageStateLeft = PageState.Loading;
395 model.notifyListeners(); 53 model.notifyListeners();
396 _getContantData(); 54 _getContantData();
@@ -407,63 +65,18 @@ class _ContantLeftPageState extends State<ContantLeftPage> { @@ -407,63 +65,18 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
407 model.userHistorysShow[index].phone == '' 65 model.userHistorysShow[index].phone == ''
408 ? '' 66 ? ''
409 : model.userHistorysShow[index].phone; 67 : model.userHistorysShow[index].phone;
410 -  
411 - return InkWell( 68 + return ContantItemPage(
412 onTap: () { 69 onTap: () {
413 if (model.userHistorysShow[index].phone != null && 70 if (model.userHistorysShow[index].phone != null &&
414 model.userHistorysShow[index].phone != '') { 71 model.userHistorysShow[index].phone != '') {
415 DialogUtil.goPhone(model.userHistorysShow[index].phone); 72 DialogUtil.goPhone(model.userHistorysShow[index].phone);
416 } 73 }
417 }, 74 },
418 - child: Column(  
419 - crossAxisAlignment: CrossAxisAlignment.start,  
420 - children: [  
421 - index == 0  
422 - ? MyDivider(  
423 - double.infinity,  
424 - ScreenUtil().setWidth(20),  
425 - color: MyColours.color_f5f5f5,  
426 - )  
427 - : Container(),  
428 - Container(  
429 - width: double.infinity,  
430 - padding: EdgeInsets.symmetric(  
431 - horizontal: ScreenUtil().setWidth(40),  
432 - vertical: ScreenUtil().setWidth(30)),  
433 - height: ScreenUtil().setWidth(74 * 2),  
434 - decoration: BoxDecoration(  
435 - border: Border(  
436 - top: index == 0  
437 - ? BorderSide(  
438 - width: ScreenUtil().setWidth(2),  
439 - color: MyColours.color_E0E0E0)  
440 - : BorderSide(  
441 - width: 0, color: Colors.transparent),  
442 - bottom: BorderSide(  
443 - width: ScreenUtil().setWidth(2),  
444 - color: MyColours.color_E0E0E0))),  
445 - child: Column(  
446 - crossAxisAlignment: CrossAxisAlignment.start,  
447 - children: [  
448 - _getNameWidget(model.userHistorysShow[index]),  
449 - VEmptyView(10),  
450 - // _getPhoneWidget(model.userHistorysShow[index])  
451 - ],  
452 - ),  
453 - )  
454 - ]), 75 + index: index,
  76 + model: contantShowModel,
  77 + data: model.userHistorysShow,
455 ); 78 );
456 }); 79 });
457 -  
458 - // onRefresh: () async {  
459 - // // offset = 0;  
460 - // // getMessages(showLoading: false);  
461 - // },  
462 - // onLoad: () async {  
463 - // // offset++;  
464 - // // getMessages(showLoading: false);  
465 - // },  
466 -  
467 } 80 }
468 }, 81 },
469 ); 82 );
1 -import 'dart:io';  
2 -  
3 import 'package:flutter/material.dart'; 1 import 'package:flutter/material.dart';
4 2
5 -import 'package:flutter_screenutil/flutter_screenutil.dart';  
6 import 'package:lpinyin/lpinyin.dart'; 3 import 'package:lpinyin/lpinyin.dart';
7 import 'package:one_key/constant/state.dart'; 4 import 'package:one_key/constant/state.dart';
8 import 'package:one_key/models/user_history_entity.dart'; 5 import 'package:one_key/models/user_history_entity.dart';
  6 +import 'package:one_key/pages/my/contant_item_page.dart';
9 import 'package:one_key/provider/contant_show_model.dart'; 7 import 'package:one_key/provider/contant_show_model.dart';
10 8
11 -import 'package:one_key/res/colors.dart';  
12 import 'package:one_key/utils/dialog_util.dart'; 9 import 'package:one_key/utils/dialog_util.dart';
13 import 'package:one_key/utils/misc.dart'; 10 import 'package:one_key/utils/misc.dart';
14 -import 'package:one_key/widgets/MyDivider.dart';  
15 11
16 import 'package:one_key/widgets/page_exception.dart'; 12 import 'package:one_key/widgets/page_exception.dart';
17 -import 'package:one_key/widgets/v_empty_view.dart'; 13 +
18 import 'package:contacts_service/contacts_service.dart'; 14 import 'package:contacts_service/contacts_service.dart';
19 import 'package:permission_handler/permission_handler.dart'; 15 import 'package:permission_handler/permission_handler.dart';
20 import 'package:provider/provider.dart'; 16 import 'package:provider/provider.dart';
@@ -27,7 +23,6 @@ class ContantRightPage extends StatefulWidget { @@ -27,7 +23,6 @@ class ContantRightPage extends StatefulWidget {
27 } 23 }
28 24
29 class _ContantRightPageState extends State<ContantRightPage> { 25 class _ContantRightPageState extends State<ContantRightPage> {
30 - // PageState _pageState = PageState.Loading;  
31 List<Contact> _contacts; 26 List<Contact> _contacts;
32 bool isNeed = false; 27 bool isNeed = false;
33 bool goSetting = false; 28 bool goSetting = false;
@@ -41,13 +36,6 @@ class _ContantRightPageState extends State<ContantRightPage> { @@ -41,13 +36,6 @@ class _ContantRightPageState extends State<ContantRightPage> {
41 }); 36 });
42 } 37 }
43 38
44 - // Future<void> _askPermissions() async {  
45 - // PermissionStatus permissionStatus = await _getContactPermission();  
46 - // if (permissionStatus != PermissionStatus.granted) {  
47 - // _handleInvalidPermissions(permissionStatus);  
48 - // }  
49 - // }  
50 -  
51 _openAddressBook() async { 39 _openAddressBook() async {
52 if (!(await checkContactPermission())) { 40 if (!(await checkContactPermission())) {
53 PermissionStatus permissionStatus = await contactPermissionStatus(); 41 PermissionStatus permissionStatus = await contactPermissionStatus();
@@ -89,42 +77,11 @@ class _ContantRightPageState extends State<ContantRightPage> { @@ -89,42 +77,11 @@ class _ContantRightPageState extends State<ContantRightPage> {
89 } 77 }
90 } 78 }
91 79
92 - // Future<PermissionStatus> _getContactPermission() async {  
93 - // PermissionStatus permission = await PermissionHandler()  
94 - // .checkPermissionStatus(PermissionGroup.contacts);  
95 - // if (permission != PermissionStatus.granted &&  
96 - // permission != PermissionStatus.disabled) {  
97 - // Map<PermissionGroup, PermissionStatus> permissionStatus =  
98 - // await PermissionHandler()  
99 - // .requestPermissions([PermissionGroup.contacts]);  
100 - // return permissionStatus[PermissionGroup.contacts] ??  
101 - // PermissionStatus.unknown;  
102 - // } else {  
103 - // return permission;  
104 - // }  
105 - // }  
106 -  
107 - // void _handleInvalidPermissions(PermissionStatus permissionStatus) {  
108 - // if (permissionStatus == PermissionStatus.denied) {  
109 - // throw PlatformException(  
110 - // code: "PERMISSION_DENIED",  
111 - // message: "Access to location data denied",  
112 - // details: null);  
113 - // } else if (permissionStatus == PermissionStatus.disabled) {  
114 - // throw PlatformException(  
115 - // code: "PERMISSION_DISABLED",  
116 - // message: "Location data is not available on device",  
117 - // details: null);  
118 - // }  
119 - // }  
120 -  
121 Future<void> refreshContacts() async { 80 Future<void> refreshContacts() async {
122 - // Load without thumbnails initially.  
123 List<Contact> contacts = (await ContactsService.getContacts( 81 List<Contact> contacts = (await ContactsService.getContacts(
124 withThumbnails: false, iOSLocalizedLabels: false)) 82 withThumbnails: false, iOSLocalizedLabels: false))
125 .toList(); 83 .toList();
126 -// var contacts = (await ContactsService.getContactsForPhone("8554964652"))  
127 -// .toList(); 84 +
128 setState(() { 85 setState(() {
129 _contacts = contacts; 86 _contacts = contacts;
130 if (_contacts.length > 0) { 87 if (_contacts.length > 0) {
@@ -158,76 +115,6 @@ class _ContantRightPageState extends State<ContantRightPage> { @@ -158,76 +115,6 @@ class _ContantRightPageState extends State<ContantRightPage> {
158 contantShowModel.pageStateRight = PageState.Empty; 115 contantShowModel.pageStateRight = PageState.Empty;
159 } 116 }
160 }); 117 });
161 -  
162 - // Lazy load thumbnails after rendering initial contacts.  
163 - // for (final contact in contacts) {  
164 - // ContactsService.getAvatar(contact).then((avatar) {  
165 - // if (avatar == null) return; // Don't redraw if no change.  
166 - // setState(() => contact.avatar = avatar);  
167 - // });  
168 - // }  
169 - }  
170 -  
171 - _openContactForm() async {  
172 - try {  
173 - var contact =  
174 - await ContactsService.openContactForm(iOSLocalizedLabels: false);  
175 - refreshContacts();  
176 - } on FormOperationException catch (e) {  
177 - switch (e.errorCode) {  
178 - case FormOperationErrorCode.FORM_OPERATION_CANCELED:  
179 - case FormOperationErrorCode.FORM_COULD_NOT_BE_OPEN:  
180 - case FormOperationErrorCode.FORM_OPERATION_UNKNOWN_ERROR:  
181 - default:  
182 - print(e.errorCode);  
183 - }  
184 - }  
185 - }  
186 -  
187 - // /// app生命周期  
188 - // @override  
189 - // void didChangeAppLifecycleState(AppLifecycleState state) async {  
190 - // switch (state) {  
191 - // case AppLifecycleState.resumed: // 应用程序可见,前台  
192 - // if (!Platform.isAndroid) {  
193 - // if (isNeed) {  
194 - // isNeed = false;  
195 - // if (goSetting) {  
196 - // _getContactPemisoin();  
197 - // }  
198 - // }  
199 - // } else {  
200 - // if (goSetting) {  
201 - // _getContactPemisoin();  
202 - // }  
203 - // }  
204 - // break;  
205 - // case AppLifecycleState.paused:  
206 - // print('paused');  
207 - // // if (!Platform.isAndroid) {  
208 - // // if (!(await checkLocationPermission())) {  
209 - // // //没有定位权限  
210 - // isNeed = true;  
211 - // // } else {  
212 - // // isNeed = false;  
213 - // // }  
214 - // // }  
215 -  
216 - // break;  
217 - // default:  
218 - // break;  
219 - // }  
220 - // }  
221 -  
222 - /// 程序进入前台刷新位置权限(来回切换位置权限,及时刷新页面)  
223 - _getContactPemisoin() async {  
224 - if (await checkContactPermission()) {  
225 - userNo = false;  
226 - }  
227 - if (!userNo) {  
228 - goSetting = false;  
229 - _openAddressBook();  
230 - }  
231 } 118 }
232 119
233 @override 120 @override
@@ -254,61 +141,16 @@ class _ContantRightPageState extends State<ContantRightPage> { @@ -254,61 +141,16 @@ class _ContantRightPageState extends State<ContantRightPage> {
254 itemCount: contantShowModel.contactsShow?.length ?? 0, 141 itemCount: contantShowModel.contactsShow?.length ?? 0,
255 itemBuilder: (BuildContext context, int index) { 142 itemBuilder: (BuildContext context, int index) {
256 UserHistoryEntity c = contantShowModel.contactsShow[index]; 143 UserHistoryEntity c = contantShowModel.contactsShow[index];
257 - return InkWell(  
258 - onTap: () {  
259 - if (c.phone != null && c.phone != '') {  
260 - DialogUtil.goPhone(c.phone);  
261 - }  
262 - },  
263 - child: Column(  
264 - crossAxisAlignment: CrossAxisAlignment.start,  
265 - children: [  
266 - index == 0  
267 - ? MyDivider(  
268 - double.infinity,  
269 - ScreenUtil().setWidth(20),  
270 - color: MyColours.color_f5f5f5,  
271 - )  
272 - : Container(),  
273 - Container(  
274 - width: double.infinity,  
275 - padding: EdgeInsets.symmetric(  
276 - horizontal: ScreenUtil().setWidth(40),  
277 - vertical: ScreenUtil().setWidth(30)),  
278 - height: ScreenUtil().setWidth(74 * 2),  
279 - decoration: BoxDecoration(  
280 - border: Border(  
281 - top: index == 0  
282 - ? BorderSide(  
283 - width: ScreenUtil().setWidth(2),  
284 - color: MyColours.color_E0E0E0)  
285 - : BorderSide(  
286 - width: 0, color: Colors.transparent),  
287 - bottom: BorderSide(  
288 - width: ScreenUtil().setWidth(2),  
289 - color: MyColours.color_E0E0E0))),  
290 - child: Column(  
291 - crossAxisAlignment: CrossAxisAlignment.start,  
292 - children: [  
293 - Text(  
294 - c.rname == null || c.rname == ''  
295 - ? ''  
296 - : c.rname,  
297 - style: TextStyle(  
298 - color: MyColours.color_333333,  
299 - fontSize: ScreenUtil().setSp(32))),  
300 - VEmptyView(10),  
301 - Text(  
302 - c.phone == null || c.phone == ''  
303 - ? ''  
304 - : c.phone,  
305 - style: TextStyle(  
306 - color: MyColours.color_999999,  
307 - fontSize: ScreenUtil().setSp(30)))  
308 - ],  
309 - ),  
310 - )  
311 - ])); 144 + return ContantItemPage(
  145 + onTap: () {
  146 + if (c.phone != null && c.phone != '') {
  147 + DialogUtil.goPhone(c.phone);
  148 + }
  149 + },
  150 + index: index,
  151 + model: contantShowModel,
  152 + data: contantShowModel.contactsShow,
  153 + );
312 }); 154 });
313 } 155 }
314 }); 156 });