|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
|
|
|
import 'package:one_key/constant/state.dart';
|
|
|
|
import 'package:one_key/models/user_history_entity.dart';
|
|
|
|
|
|
|
|
import 'package:one_key/pages/my/contant_item_page.dart';
|
|
|
|
import 'package:one_key/provider/contant_show_model.dart';
|
|
|
|
import 'package:one_key/provider/user_model.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/utils/dialog_util.dart';
|
|
|
|
import 'package:one_key/utils/utils.dart';
|
|
|
|
import 'package:one_key/widgets/MyDivider.dart';
|
|
|
|
|
|
|
|
import 'package:one_key/widgets/page_exception.dart';
|
|
|
|
import 'package:one_key/widgets/v_empty_view.dart';
|
|
|
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class ContantLeftPage extends StatefulWidget {
|
|
...
|
...
|
@@ -42,344 +40,6 @@ class _ContantLeftPageState extends State<ContantLeftPage> { |
|
|
|
await contantShowModel.getUserHistorys(context, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getWidget(String title, String key) {
|
|
|
|
return RichText(
|
|
|
|
text: TextSpan(children: getTextSpanList(title, searchContent: key)));
|
|
|
|
}
|
|
|
|
|
|
|
|
///关键字在前面布局
|
|
|
|
_startPlaceWidget(
|
|
|
|
String title, String key, UserHistoryEntity userHistoryEntity) {
|
|
|
|
String keyTemp = '';
|
|
|
|
if (Utils.isChinese(key)) {
|
|
|
|
keyTemp = key;
|
|
|
|
} else {
|
|
|
|
String name =
|
|
|
|
userHistoryEntity.rname == null || userHistoryEntity.rname == ''
|
|
|
|
? ''
|
|
|
|
: 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)) {
|
|
|
|
keyTemp = name.substring(
|
|
|
|
pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
print(keyTemp);
|
|
|
|
}
|
|
|
|
return _getWidget(title, keyTemp);
|
|
|
|
// return RichText(
|
|
|
|
// maxLines: 1,
|
|
|
|
// overflow: TextOverflow.ellipsis,
|
|
|
|
// text: TextSpan(
|
|
|
|
// children: [
|
|
|
|
// TextSpan(
|
|
|
|
// text: keyTemp,
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: ScreenUtil().setSp(32),
|
|
|
|
// color: MyColours.color_199095),
|
|
|
|
// ),
|
|
|
|
// TextSpan(
|
|
|
|
// text: title.replaceAll(keyTemp, ''),
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: ScreenUtil().setSp(32),
|
|
|
|
// color: MyColours.color_333333),
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// ));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ///关键字在后面布局
|
|
|
|
// _endlaceWidget(
|
|
|
|
// String title, String key, UserHistoryEntity userHistoryEntity) {
|
|
|
|
// String keyTemp = '';
|
|
|
|
// if (Utils.isChinese(key)) {
|
|
|
|
// keyTemp = key;
|
|
|
|
// } else if (Utils.isPinyin(key)) {
|
|
|
|
// String name =
|
|
|
|
// userHistoryEntity.rname == null || userHistoryEntity.rname == ''
|
|
|
|
// ? ''
|
|
|
|
// : userHistoryEntity.rname;
|
|
|
|
// String pinyinFirst = userHistoryEntity.pinyinFirst;
|
|
|
|
// List<String> pinyinList = userHistoryEntity.pinyinList;
|
|
|
|
// 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);
|
|
|
|
// }
|
|
|
|
// print(keyTemp);
|
|
|
|
// }
|
|
|
|
// return RichText(
|
|
|
|
// maxLines: 1,
|
|
|
|
// overflow: TextOverflow.ellipsis,
|
|
|
|
// text: TextSpan(
|
|
|
|
// children: [
|
|
|
|
// TextSpan(
|
|
|
|
// text: title.replaceAll(keyTemp, ''),
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: ScreenUtil().setSp(32),
|
|
|
|
// color: MyColours.color_333333),
|
|
|
|
// ),
|
|
|
|
// TextSpan(
|
|
|
|
// text: keyTemp,
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: ScreenUtil().setSp(32),
|
|
|
|
// color: MyColours.color_199095),
|
|
|
|
// ),
|
|
|
|
// ],
|
|
|
|
// ));
|
|
|
|
// }
|
|
|
|
|
|
|
|
// ///关键字在中间布局
|
|
|
|
// _middlePlaceWidget(
|
|
|
|
// String title, String key, UserHistoryEntity userHistoryEntity) {
|
|
|
|
// String keyTemp = '';
|
|
|
|
// if (Utils.isChinese(key)) {
|
|
|
|
// keyTemp = key;
|
|
|
|
// } else if (Utils.isPinyin(key)) {
|
|
|
|
// String name =
|
|
|
|
// userHistoryEntity.rname == null || userHistoryEntity.rname == ''
|
|
|
|
// ? ''
|
|
|
|
// : userHistoryEntity.rname;
|
|
|
|
// String pinyinFirst = userHistoryEntity.pinyinFirst;
|
|
|
|
// List<String> pinyinList = userHistoryEntity.pinyinList;
|
|
|
|
// String pinyin = userHistoryEntity.pinyin;
|
|
|
|
// if (pinyinFirst.contains(key)) {
|
|
|
|
// keyTemp = name.substring(
|
|
|
|
// pinyinFirst.indexOf(key), pinyinFirst.indexOf(key) + 1);
|
|
|
|
// } else if (pinyinList.indexOf(key) != -1) {
|
|
|
|
// keyTemp = name.substring(
|
|
|
|
// pinyinList.indexOf(key), pinyinList.indexOf(key) + 1);
|
|
|
|
// }
|
|
|
|
// print(keyTemp);
|
|
|
|
// }
|
|
|
|
// return RichText(
|
|
|
|
// maxLines: 1,
|
|
|
|
// overflow: TextOverflow.ellipsis,
|
|
|
|
// text: TextSpan(
|
|
|
|
// children: [
|
|
|
|
// TextSpan(
|
|
|
|
// text: title.substring(0, title.indexOf(keyTemp)),
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: ScreenUtil().setSp(32),
|
|
|
|
// color: MyColours.color_333333),
|
|
|
|
// ),
|
|
|
|
// TextSpan(
|
|
|
|
// text: keyTemp,
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: ScreenUtil().setSp(32),
|
|
|
|
// color: MyColours.color_199095),
|
|
|
|
// ),
|
|
|
|
// TextSpan(
|
|
|
|
// text: title.substring(
|
|
|
|
// title.lastIndexOf(keyTemp) + keyTemp.length, title.length),
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: ScreenUtil().setSp(32),
|
|
|
|
// color: MyColours.color_333333)),
|
|
|
|
// ],
|
|
|
|
// ),
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
|
|
|
|
List<TextSpan> getTextSpanList(String textContent,
|
|
|
|
{String searchContent = '',
|
|
|
|
String frontContent = '',
|
|
|
|
int fontSize = 32,
|
|
|
|
Color fontColor = MyColours.color_333333,
|
|
|
|
Color selectFontColor = MyColours.color_199095}) {
|
|
|
|
List<TextSpan> textSpanList = [];
|
|
|
|
|
|
|
|
if (frontContent.isEmpty == false) {
|
|
|
|
textSpanList.add(TextSpan(
|
|
|
|
text: frontContent,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(fontSize), color: fontColor)));
|
|
|
|
}
|
|
|
|
|
|
|
|
///搜索内容不为空并且 显示内容中存在与搜索内容相同的文字
|
|
|
|
if (searchContent != null &&
|
|
|
|
searchContent.isEmpty == false &&
|
|
|
|
textContent.contains(searchContent)) {
|
|
|
|
List<Map> _strMapList = [];
|
|
|
|
bool _isContains = true;
|
|
|
|
while (_isContains) {
|
|
|
|
int startIndex = textContent.indexOf(searchContent);
|
|
|
|
String showStr = textContent.substring(
|
|
|
|
startIndex, startIndex + searchContent.length);
|
|
|
|
Map _strMap;
|
|
|
|
if (startIndex > 0) {
|
|
|
|
String normalStr = textContent.substring(0, startIndex);
|
|
|
|
_strMap = Map();
|
|
|
|
_strMap['content'] = normalStr;
|
|
|
|
_strMap['isHighlight'] = false;
|
|
|
|
_strMapList.add(_strMap);
|
|
|
|
}
|
|
|
|
_strMap = Map();
|
|
|
|
_strMap['content'] = showStr;
|
|
|
|
_strMap['isHighlight'] = true;
|
|
|
|
_strMapList.add(_strMap);
|
|
|
|
textContent = textContent.substring(
|
|
|
|
startIndex + searchContent.length, textContent.length);
|
|
|
|
|
|
|
|
_isContains = textContent.contains(searchContent);
|
|
|
|
if (!_isContains && textContent != '') {
|
|
|
|
_strMap = Map();
|
|
|
|
_strMap['content'] = textContent;
|
|
|
|
_strMap['isHighlight'] = false;
|
|
|
|
_strMapList.add(_strMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_strMapList.forEach((map) {
|
|
|
|
textSpanList.add(TextSpan(
|
|
|
|
text: map['content'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenUtil().setSp(fontSize),
|
|
|
|
color: map['isHighlight'] ? selectFontColor : fontColor)));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
///正常显示所有文字
|
|
|
|
textSpanList.add(TextSpan(
|
|
|
|
text: textContent,
|
|
|
|
style:
|
|
|
|
TextStyle(fontSize: ScreenUtil().setSp(fontSize), color: fontColor),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return textSpanList;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getNameWidget(UserHistoryEntity userHistoryEntity) {
|
|
|
|
String name =
|
|
|
|
userHistoryEntity.rname == null || userHistoryEntity.rname == ''
|
|
|
|
? ''
|
|
|
|
: userHistoryEntity.rname;
|
|
|
|
// String phone =
|
|
|
|
// userHistoryEntity.phone == null || userHistoryEntity.phone == ''
|
|
|
|
// ? ''
|
|
|
|
// : userHistoryEntity.phone;
|
|
|
|
String key = contantShowModel.controller.text;
|
|
|
|
String pinyinFirst = userHistoryEntity.pinyinFirst;
|
|
|
|
List<String> pinyinList = userHistoryEntity.pinyinList;
|
|
|
|
String pinyin = userHistoryEntity.pinyin;
|
|
|
|
if (key == '') {
|
|
|
|
return Text(name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_333333, fontSize: ScreenUtil().setSp(32)));
|
|
|
|
} else {
|
|
|
|
if (Utils.isChinese(key) || Utils.isNum(key)) {
|
|
|
|
return name.contains(key) && name.length != key.length
|
|
|
|
? _startPlaceWidget(name, key, userHistoryEntity)
|
|
|
|
: Text(name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: name.length == key.length
|
|
|
|
? MyColours.color_199095
|
|
|
|
: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(32)));
|
|
|
|
} else if (Utils.isPinyin(key)) {
|
|
|
|
if (!pinyinFirst.contains(key) && !pinyinList.contains(key)) {
|
|
|
|
return Text(name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(32)));
|
|
|
|
} else {
|
|
|
|
if (pinyinFirst.contains(key)) {
|
|
|
|
return pinyinFirst.contains(key) && pinyinFirst.length != key.length
|
|
|
|
? Row(
|
|
|
|
children: <Widget>[
|
|
|
|
pinyinFirst.startsWith(key)
|
|
|
|
? _startPlaceWidget(name, key, userHistoryEntity)
|
|
|
|
: Text(''),
|
|
|
|
(pinyinFirst.length != key.length &&
|
|
|
|
pinyinFirst.endsWith(key))
|
|
|
|
? _startPlaceWidget(name, key, userHistoryEntity)
|
|
|
|
: Text(''),
|
|
|
|
(!pinyinFirst.endsWith(key) &&
|
|
|
|
!pinyinFirst.startsWith(key))
|
|
|
|
? _startPlaceWidget(name, key, userHistoryEntity)
|
|
|
|
: Text('')
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Text(name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: pinyinFirst.length == key.length
|
|
|
|
? MyColours.color_199095
|
|
|
|
: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(32)));
|
|
|
|
} else if (pinyinList.contains(key)) {
|
|
|
|
return pinyinList.contains(key) && pinyin.length != key.length
|
|
|
|
? Row(
|
|
|
|
children: <Widget>[
|
|
|
|
pinyin.startsWith(key)
|
|
|
|
? _startPlaceWidget(name, key, userHistoryEntity)
|
|
|
|
: Text(''),
|
|
|
|
pinyin.endsWith(key)
|
|
|
|
? _startPlaceWidget(name, key, userHistoryEntity)
|
|
|
|
: Text(''),
|
|
|
|
(!pinyin.endsWith(key) && !pinyin.startsWith(key))
|
|
|
|
? _startPlaceWidget(name, key, userHistoryEntity)
|
|
|
|
: Text('')
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Text(name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(32)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return Text(name,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(32)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getPhoneWidget(UserHistoryEntity userHistoryEntity) {
|
|
|
|
String phone =
|
|
|
|
userHistoryEntity.phone == null || userHistoryEntity.phone == ''
|
|
|
|
? ''
|
|
|
|
: userHistoryEntity.phone;
|
|
|
|
String key = contantShowModel.controller.text;
|
|
|
|
String pinyinFirst = userHistoryEntity.pinyinFirst;
|
|
|
|
List<String> pinyinList = userHistoryEntity.pinyinList;
|
|
|
|
String pinyin = userHistoryEntity.pinyin;
|
|
|
|
if (key == '') {
|
|
|
|
return Text(phone,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_999999, fontSize: ScreenUtil().setSp(30)));
|
|
|
|
} else {
|
|
|
|
if (Utils.isNum(key)) {
|
|
|
|
return phone.contains(key) && phone.length != key.length
|
|
|
|
? Row(
|
|
|
|
children: <Widget>[
|
|
|
|
phone.startsWith(key) ||
|
|
|
|
pinyinFirst.startsWith(key) ||
|
|
|
|
pinyinList[0] == key
|
|
|
|
? _startPlaceWidget(phone, key, userHistoryEntity)
|
|
|
|
: Text(''),
|
|
|
|
(phone.length != key.length && phone.endsWith(key))
|
|
|
|
? _startPlaceWidget(phone, key, userHistoryEntity)
|
|
|
|
: Text(''),
|
|
|
|
(!phone.endsWith(key) && !phone.startsWith(key))
|
|
|
|
? _startPlaceWidget(phone, key, userHistoryEntity)
|
|
|
|
: Text('')
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Text(phone,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_999999,
|
|
|
|
fontSize: ScreenUtil().setSp(30)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
contantShowModel = Provider.of<ContantShowModel>(context, listen: true);
|
|
...
|
...
|
@@ -389,8 +49,6 @@ class _ContantLeftPageState extends State<ContantLeftPage> { |
|
|
|
return ExceptionPage(
|
|
|
|
pageState: model.pageStateLeft,
|
|
|
|
callback: () {
|
|
|
|
// offset = 0;
|
|
|
|
// getMessages();
|
|
|
|
model.pageStateLeft = PageState.Loading;
|
|
|
|
model.notifyListeners();
|
|
|
|
_getContantData();
|
|
...
|
...
|
@@ -407,63 +65,18 @@ class _ContantLeftPageState extends State<ContantLeftPage> { |
|
|
|
model.userHistorysShow[index].phone == ''
|
|
|
|
? ''
|
|
|
|
: model.userHistorysShow[index].phone;
|
|
|
|
|
|
|
|
return InkWell(
|
|
|
|
return ContantItemPage(
|
|
|
|
onTap: () {
|
|
|
|
if (model.userHistorysShow[index].phone != null &&
|
|
|
|
model.userHistorysShow[index].phone != '') {
|
|
|
|
DialogUtil.goPhone(model.userHistorysShow[index].phone);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
index == 0
|
|
|
|
? MyDivider(
|
|
|
|
double.infinity,
|
|
|
|
ScreenUtil().setWidth(20),
|
|
|
|
color: MyColours.color_f5f5f5,
|
|
|
|
)
|
|
|
|
: Container(),
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: ScreenUtil().setWidth(40),
|
|
|
|
vertical: ScreenUtil().setWidth(30)),
|
|
|
|
height: ScreenUtil().setWidth(74 * 2),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
top: index == 0
|
|
|
|
? BorderSide(
|
|
|
|
width: ScreenUtil().setWidth(2),
|
|
|
|
color: MyColours.color_E0E0E0)
|
|
|
|
: BorderSide(
|
|
|
|
width: 0, color: Colors.transparent),
|
|
|
|
bottom: BorderSide(
|
|
|
|
width: ScreenUtil().setWidth(2),
|
|
|
|
color: MyColours.color_E0E0E0))),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
_getNameWidget(model.userHistorysShow[index]),
|
|
|
|
VEmptyView(10),
|
|
|
|
// _getPhoneWidget(model.userHistorysShow[index])
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
index: index,
|
|
|
|
model: contantShowModel,
|
|
|
|
data: model.userHistorysShow,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
// onRefresh: () async {
|
|
|
|
// // offset = 0;
|
|
|
|
// // getMessages(showLoading: false);
|
|
|
|
// },
|
|
|
|
// onLoad: () async {
|
|
|
|
// // offset++;
|
|
|
|
// // getMessages(showLoading: false);
|
|
|
|
// },
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
...
|
...
|
|