Commit daa1e20660de949bee13434ee8356bc1960b05e5

Authored by wdn127929
1 parent 40d88265

搜索

... ... @@ -22,7 +22,9 @@ class UserHistoryEntity extends Object {
@JsonKey(name: 'cusdem')
String cusdem;
String pinyin;
List<String> pinyinList; //全拼数组
String pinyin; //全拼字母
String pinyinFirst; //首字母
UserHistoryEntity(
this.id,
... ...
... ... @@ -2,10 +2,12 @@ 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/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';
... ... @@ -40,6 +42,344 @@ 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);
... ... @@ -63,6 +403,11 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
return ListView.builder(
itemCount: model.userHistorysShow.length,
itemBuilder: (BuildContext context, int index) {
String phone = model.userHistorysShow[index].phone == null ||
model.userHistorysShow[index].phone == ''
? ''
: model.userHistorysShow[index].phone;
return InkWell(
onTap: () {
if (model.userHistorysShow[index].phone != null &&
... ... @@ -100,23 +445,9 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
model.userHistorysShow[index].rname == null ||
model.userHistorysShow[index].rname == ''
? ''
: model.userHistorysShow[index].rname,
style: TextStyle(
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(32))),
_getNameWidget(model.userHistorysShow[index]),
VEmptyView(10),
Text(
model.userHistorysShow[index].phone == null ||
model.userHistorysShow[index].phone == ''
? ''
: model.userHistorysShow[index].phone,
style: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(30)))
// _getPhoneWidget(model.userHistorysShow[index])
],
),
)
... ...
... ... @@ -25,7 +25,7 @@ class _ContactListPageState extends State<ContactListPage>
List<Contact> _contacts;
List _tabBarTitle;
TabController tabController;
TextEditingController controller = TextEditingController();
ContantShowModel contantShowModel;
@override
void initState() {
... ... @@ -37,129 +37,145 @@ class _ContactListPageState extends State<ContactListPage>
@override
Widget build(BuildContext context) {
contantShowModel = Provider.of<ContantShowModel>(context, listen: true);
return Scaffold(
backgroundColor: MyColours.color_ffffff,
appBar: SystemAppBar(
'联系人',
onTap: () {
EventBus().emit('changeStatusColor');
Navigator.of(context).pop();
},
),
body: WillPopScope(
child: SafeArea(
child: Column(
children: <Widget>[
Container(
// color: Colors.red,
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
vertical: ScreenUtil().setWidth(10)),
height: ScreenUtil().setWidth(45 * 2),
// alignment: Alignment.center,
child: Container(
alignment: Alignment.center,
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(20 * 2),
vertical: ScreenUtil().setWidth(14)),
decoration: BoxDecoration(
color: MyColours.color_F0F0F0,
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(24 * 2))),
child: TextField(
controller: controller,
// focusNode: _focusNode,
// autofocus: true,
return Material(
child: InkWell(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
},
child: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: MyColours.color_ffffff,
appBar: SystemAppBar(
'联系人',
onTap: () {
EventBus().emit('changeStatusColor');
Navigator.of(context).pop();
},
),
body: WillPopScope(
child: SafeArea(
child: Column(
children: <Widget>[
Container(
// color: Colors.red,
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(40),
vertical: ScreenUtil().setWidth(10)),
height: ScreenUtil().setWidth(45 * 2),
// alignment: Alignment.center,
child: Container(
alignment: Alignment.center,
padding: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(20 * 2),
vertical: ScreenUtil().setWidth(14)),
decoration: BoxDecoration(
color: MyColours.color_F0F0F0,
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(24 * 2))),
child: TextField(
controller: contantShowModel.controller,
// focusNode: _focusNode,
// autofocus: true,
style: TextStyle(
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(30),
textBaseline: TextBaseline.alphabetic),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
hintText: "搜索联系人",
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(30),
),
isCollapsed:
true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度
border: InputBorder.none,
//左边图标设置
icon: Image.asset(
Utils.getImgPath('search'),
width: ScreenUtil().setWidth(30),
),
//右边图标设置
suffixIcon: GestureDetector(
child: Container(
height: ScreenUtil().setWidth(30),
width: ScreenUtil().setWidth(30),
alignment: Alignment.centerRight,
child: Image.asset(
Utils.getImgPath('clear'),
width: ScreenUtil().setWidth(30),
),
style: TextStyle(
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(30),
textBaseline: TextBaseline.alphabetic),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
hintText: "搜索联系人",
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(30),
),
isCollapsed:
true, //重点,相当于高度包裹的意思,必须设置为true,不然有默认奇妙的最小高度
border: InputBorder.none,
//左边图标设置
icon: Image.asset(
Utils.getImgPath('search'),
width: ScreenUtil().setWidth(30),
),
//右边图标设置
suffixIcon: contantShowModel
.controller.text ==
''
? Container()
: GestureDetector(
child: Container(
height: ScreenUtil().setWidth(30),
width: ScreenUtil().setWidth(30),
alignment: Alignment.centerRight,
child: Image.asset(
Utils.getImgPath('clear'),
width:
ScreenUtil().setWidth(30),
),
),
onTap: () {
WidgetsBinding.instance
.addPostFrameCallback(((_) {
contantShowModel.controller
.clear();
contantShowModel.searchData('');
}));
},
)),
keyboardType: TextInputType.text,
textInputAction: TextInputAction.search,
onChanged: (value) {
setState(() {});
// _searchSellerLocation();
contantShowModel.searchData(value);
},
onEditingComplete: () {
// _searchSellerLocation();
// _focusNode.unfocus();
},
),
onTap: () {
WidgetsBinding.instance.addPostFrameCallback(
((_) => controller.clear()));
},
)),
keyboardType: TextInputType.text,
textInputAction: TextInputAction.search,
onChanged: (value) {
setState(() {});
// _searchSellerLocation();
contantShowModel.searchData(value);
},
onEditingComplete: () {
// _searchSellerLocation();
// _focusNode.unfocus();
},
),
Container(
padding: EdgeInsets.only(
bottom: ScreenUtil().setWidth(10)),
margin: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(30)),
child: TabBar(
controller: tabController,
indicator: CustomTabIndicator(
radius: 0,
),
indicatorColor: MyColours.color_199095,
indicatorSize: TabBarIndicatorSize.tab,
// indicatorPadding: EdgeInsets.symmetric(
// horizontal: ScreenUtil().setWidth(12)),
labelColor: MyColours.color_199095,
labelStyle: TextStyle(
fontSize: ScreenUtil().setSp(32),
fontWeight: FontWeight.bold),
labelPadding: EdgeInsets.zero,
unselectedLabelStyle:
TextStyle(fontWeight: FontWeight.normal),
unselectedLabelColor: MyColours.color_999999,
tabs: _tabBarTitle.map((value) {
return Tab(
child: Text(value),
);
}).toList()),
),
Expanded(
child: TabBarView(
controller: tabController,
// physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ContantLeftPage(),
ContantRightPage(),
],
)),
],
)),
Container(
padding: EdgeInsets.only(bottom: ScreenUtil().setWidth(10)),
margin: EdgeInsets.symmetric(
horizontal: ScreenUtil().setWidth(30)),
child: TabBar(
controller: tabController,
indicator: CustomTabIndicator(
radius: 0,
),
indicatorColor: MyColours.color_199095,
indicatorSize: TabBarIndicatorSize.tab,
// indicatorPadding: EdgeInsets.symmetric(
// horizontal: ScreenUtil().setWidth(12)),
labelColor: MyColours.color_199095,
labelStyle: TextStyle(
fontSize: ScreenUtil().setSp(32),
fontWeight: FontWeight.bold),
labelPadding: EdgeInsets.zero,
unselectedLabelStyle:
TextStyle(fontWeight: FontWeight.normal),
unselectedLabelColor: MyColours.color_999999,
tabs: _tabBarTitle.map((value) {
return Tab(
child: Text(value),
);
}).toList()),
),
Expanded(
child: TabBarView(
controller: tabController,
// physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ContantLeftPage(),
ContantRightPage(),
],
)),
],
)),
onWillPop: () async {
EventBus().emit('changeStatusColor');
return true;
}));
onWillPop: () async {
EventBus().emit('changeStatusColor');
return true;
}))));
}
}
... ...
... ... @@ -128,6 +128,7 @@ class _ContantRightPageState extends State<ContantRightPage> {
setState(() {
_contacts = contacts;
if (_contacts.length > 0) {
contantShowModel.contacts = [];
for (int i = 0; i < _contacts.length; i++) {
UserHistoryEntity item = UserHistoryEntity(
'',
... ... @@ -136,8 +137,19 @@ class _ContantRightPageState extends State<ContantRightPage> {
'',
_contacts[i].phones.first.value,
'');
item.pinyin =
item.pinyin = PinyinHelper.getPinyin(_contacts[i].displayName);
item.pinyin = PinyinHelper.getPinyin(_contacts[i].displayName)
.replaceAll(' ', '');
item.pinyinList =
PinyinHelper.getPinyin(_contacts[i].displayName).split(' ');
item.pinyinFirst = '';
for (int j = 0; j < item.pinyinList.length; j++) {
String letter = item.pinyinList[j];
if (letter.length > 0) {
item.pinyinFirst += item.pinyinList[j].substring(0, 1);
} else {
item.pinyinFirst += '';
}
}
contantShowModel.contacts.add(item);
}
contantShowModel.contactsShow = contantShowModel.contacts;
... ...
... ... @@ -16,6 +16,7 @@ class ContantShowModel extends ChangeNotifier {
List<UserHistoryEntity> contacts = []; //手机通讯录(总)
List<UserHistoryEntity> userHistorysShow = []; //历史录入展示
List<UserHistoryEntity> contactsShow = []; //手机通讯录展示
TextEditingController controller = TextEditingController(); //搜索框
//获取历史录入
getUserHistorys(BuildContext context, Map<String, String> params) async {
... ... @@ -48,7 +49,17 @@ class ContantShowModel extends ChangeNotifier {
} else {
for (int i = 0; i < userHistorys.length; i++) {
UserHistoryEntity item = userHistorys[i];
item.pinyin = PinyinHelper.getPinyin(item.rname);
item.pinyin = PinyinHelper.getPinyin(item.rname).replaceAll(' ', '');
item.pinyinList = PinyinHelper.getPinyin(item.rname).split(' ');
item.pinyinFirst = '';
for (int j = 0; j < item.pinyinList.length; j++) {
String letter = item.pinyinList[j];
if (letter.length > 0) {
item.pinyinFirst += item.pinyinList[j].substring(0, 1);
} else {
item.pinyinFirst += '';
}
}
userHistorys[i] = item;
}
userHistorysShow = userHistorys;
... ... @@ -59,31 +70,50 @@ class ContantShowModel extends ChangeNotifier {
}
searchData(String key) {
userHistorysShow = [];
contactsShow = [];
// for (int i = 0; i < userHistorys.length; i++) {
// String name = userHistorys[i].rname;
// String pinyin = userHistorys[i].pinyin;
// String phone = userHistorys[i].phone;
// if (name.contains(key) || pinyin.contains(key) || phone.contains(key)) {
// userHistorysShow.add(userHistorys[i]);
// }
// }
for (int i = 0; i < contacts.length; i++) {
String name = contacts[i].rname;
String pinyin = contacts[i].pinyin;
String phone = contacts[i].phone;
if (name.contains(key) || pinyin.contains(key) || phone.contains(key)) {
contactsShow.add(contacts[i]);
if (key == '') {
userHistorysShow = userHistorys;
contactsShow = contacts;
pageStateRight = PageState.Success;
pageStateLeft = PageState.Success;
} else {
userHistorysShow = [];
contactsShow = [];
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 phone = userHistorys[i].phone;
if (name.contains(key) ||
pinyinFirst.contains(key) ||
phone.contains(key) ||
pinyinList.contains(key)) {
userHistorysShow.add(userHistorys[i]);
}
}
for (int i = 0; i < contacts.length; i++) {
String name = contacts[i].rname;
String pinyinFirst = contacts[i].pinyinFirst;
List<String> pinyinList = contacts[i].pinyinList;
String phone = contacts[i].phone;
if (name.contains(key) ||
pinyinFirst.contains(key) ||
phone.contains(key) ||
pinyinList.contains(key)) {
contactsShow.add(contacts[i]);
}
}
if (userHistorysShow.length == 0) {
pageStateLeft = PageState.Empty;
} else {
pageStateLeft = PageState.Success;
}
if (contactsShow.length == 0) {
pageStateRight = PageState.Empty;
} else {
pageStateRight = PageState.Success;
}
}
if (userHistorysShow.length == 0) {
pageStateLeft = PageState.Empty;
}
if (contactsShow.length == 0) {
pageStateRight = PageState.Empty;
}
notifyListeners();
}
}
... ...
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';
... ... @@ -28,6 +29,28 @@ import '../app.dart';
typedef BookTimeSetCallback = void Function(bool needChange);
class Utils {
static List<String> stringToList(String str) {
List<String> list = <String>[];
// for (var value in JsonDecoder().convert(str)) {
// list.add(value);
// }
list = jsonDecode(str);
return list;
}
// 正则验证
static bool isChinese(String value) {
return RegExp(r"[\u4e00-\u9fa5]").hasMatch(value);
}
static bool isNum(String value) {
return RegExp(r'^[0-9]*$').hasMatch(value);
}
static bool isPinyin(String value) {
return RegExp(r'^[A-Za-z]+$').hasMatch(value);
}
/**
* 获取图片后缀
*
... ...