Commit 40d88265e06ffed07bb9c88b94f72697dc9f61ff

Authored by wdn127929
1 parent 7b7c9b6c

联系人搜索部分

... ... @@ -11,14 +11,14 @@ if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = "260"
def flutterVersionCode = "261"
if (flutterVersionCode == null) {
flutterVersionCode = '260'
flutterVersionCode = '261'
}
def flutterVersionName = "2.6.0"
def flutterVersionName = "2.6.1"
if (flutterVersionName == null) {
flutterVersionName = '2.6.0'
flutterVersionName = '2.6.1'
}
apply plugin: 'com.android.application'
... ...
... ... @@ -472,7 +472,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 250;
CURRENT_PROJECT_VERSION = 251;
DEVELOPMENT_TEAM = 8J59HM8B82;
ENABLE_BITCODE = NO;
FLUTTER_BUILD_MODE = release;
... ... @@ -616,7 +616,7 @@
CODE_SIGN_ENTITLEMENTS = "Runner/一键订Debug.entitlements";
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 250;
CURRENT_PROJECT_VERSION = 251;
DEVELOPMENT_TEAM = 8J59HM8B82;
ENABLE_BITCODE = NO;
FLUTTER_BUILD_MODE = release;
... ... @@ -651,7 +651,7 @@
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 250;
CURRENT_PROJECT_VERSION = 251;
DEVELOPMENT_TEAM = 8J59HM8B82;
ENABLE_BITCODE = NO;
FLUTTER_BUILD_MODE = release;
... ...
... ... @@ -2,10 +2,8 @@ import 'package:json_annotation/json_annotation.dart';
part 'user_history_entity.g.dart';
@JsonSerializable()
class UserHistoryEntity extends Object {
@JsonKey(name: 'id')
String id;
... ... @@ -24,12 +22,19 @@ class UserHistoryEntity extends Object {
@JsonKey(name: 'cusdem')
String cusdem;
UserHistoryEntity(this.id,this.sid,this.rname,this.sex,this.phone,this.cusdem,);
String pinyin;
factory UserHistoryEntity.fromJson(Map<String, dynamic> srcJson) => _$UserHistoryEntityFromJson(srcJson);
UserHistoryEntity(
this.id,
this.sid,
this.rname,
this.sex,
this.phone,
this.cusdem,
);
Map<String, dynamic> toJson() => _$UserHistoryEntityToJson(this);
factory UserHistoryEntity.fromJson(Map<String, dynamic> srcJson) =>
_$UserHistoryEntityFromJson(srcJson);
Map<String, dynamic> toJson() => _$UserHistoryEntityToJson(this);
}
... ...
... ... @@ -61,7 +61,7 @@ class _IfNeedCreateStoreItemState extends State<IfNeedCreateStoreItem> {
fontSize: ScreenUtil().setWidth(30),
color: MyColours.color_333333)),
VEmptyView(10),
Text('店长',
Text('${widget.model.roleName}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
... ...
... ... @@ -61,13 +61,13 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
);
} else {
return ListView.builder(
itemCount: model.userHistorys.length,
itemCount: model.userHistorysShow.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: () {
if (model.userHistorys[index].phone != null &&
model.userHistorys[index].phone != '') {
DialogUtil.goPhone(model.userHistorys[index].phone);
if (model.userHistorysShow[index].phone != null &&
model.userHistorysShow[index].phone != '') {
DialogUtil.goPhone(model.userHistorysShow[index].phone);
}
},
child: Column(
... ... @@ -101,19 +101,19 @@ class _ContantLeftPageState extends State<ContantLeftPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
model.userHistorys[index].rname == null ||
model.userHistorys[index].rname == ''
model.userHistorysShow[index].rname == null ||
model.userHistorysShow[index].rname == ''
? ''
: model.userHistorys[index].rname,
: model.userHistorysShow[index].rname,
style: TextStyle(
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(32))),
VEmptyView(10),
Text(
model.userHistorys[index].phone == null ||
model.userHistorys[index].phone == ''
model.userHistorysShow[index].phone == null ||
model.userHistorysShow[index].phone == ''
? ''
: model.userHistorys[index].phone,
: model.userHistorysShow[index].phone,
style: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(30)))
... ...
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:contacts_service/contacts_service.dart';
import 'package:flutter_screenutil/screenutil.dart';
import 'package:intl/intl.dart';
import 'package:one_key/pages/my/contant_left_page.dart';
import 'package:one_key/pages/my/contant_right_page.dart';
import 'package:one_key/provider/contant_show_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/utils/event_bus.dart';
import 'package:one_key/utils/misc.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/custom_tab_indicator.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
class ContactListPage extends StatefulWidget {
... ... @@ -28,7 +25,8 @@ class _ContactListPageState extends State<ContactListPage>
List<Contact> _contacts;
List _tabBarTitle;
TabController tabController;
TextEditingController controller = TextEditingController();
ContantShowModel contantShowModel;
@override
void initState() {
_tabBarTitle = ['预订联系人', '手机联系人'];
... ... @@ -38,6 +36,7 @@ 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(
... ... @@ -52,6 +51,75 @@ class _ContactListPageState extends State<ContactListPage>
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,
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),
),
),
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)),
... ... @@ -83,10 +151,8 @@ class _ContactListPageState extends State<ContactListPage>
controller: tabController,
// physics: NeverScrollableScrollPhysics(),
children: <Widget>[
ChangeNotifierProvider<ContantShowModel>(
create: (_) => ContantShowModel(),
child: ContantLeftPage()),
ContantRightPage()
ContantLeftPage(),
ContantRightPage(),
],
)),
],
... ...
... ... @@ -3,7 +3,10 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lpinyin/lpinyin.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/res/colors.dart';
import 'package:one_key/utils/dialog_util.dart';
... ... @@ -14,6 +17,7 @@ import 'package:one_key/widgets/page_exception.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:contacts_service/contacts_service.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
class ContantRightPage extends StatefulWidget {
ContantRightPage({Key key}) : super(key: key);
... ... @@ -23,15 +27,18 @@ class ContantRightPage extends StatefulWidget {
}
class _ContantRightPageState extends State<ContantRightPage> {
PageState _pageState = PageState.Loading;
// PageState _pageState = PageState.Loading;
List<Contact> _contacts;
bool isNeed = false;
bool goSetting = false;
bool userNo = false;
ContantShowModel contantShowModel;
@override
void initState() {
super.initState();
_openAddressBook();
WidgetsBinding.instance.addPostFrameCallback((_) {
_openAddressBook();
});
}
// Future<void> _askPermissions() async {
... ... @@ -49,7 +56,7 @@ class _ContantRightPageState extends State<ContantRightPage> {
print('never');
userNo = true;
setState(() {
_pageState = PageState.NoPermission;
contantShowModel.pageStateRight = PageState.NoPermission;
});
// DialogUtil.openAlertDialog(
// context, '未获得通讯录权限', "请在手机的权限管理里,将通讯录权限开启", '去设置', 340.0,
... ... @@ -65,7 +72,7 @@ class _ContantRightPageState extends State<ContantRightPage> {
refreshContacts();
} else {
setState(() {
_pageState = PageState.NoPermission;
contantShowModel.pageStateRight = PageState.NoPermission;
});
//拒绝通讯录权限 , 苹果拒绝权限后,不再提示权限框,进入此处
// DialogUtil.openAlertDialog(
... ... @@ -113,7 +120,7 @@ class _ContantRightPageState extends State<ContantRightPage> {
Future<void> refreshContacts() async {
// Load without thumbnails initially.
var contacts = (await ContactsService.getContacts(
List<Contact> contacts = (await ContactsService.getContacts(
withThumbnails: false, iOSLocalizedLabels: false))
.toList();
// var contacts = (await ContactsService.getContactsForPhone("8554964652"))
... ... @@ -121,9 +128,22 @@ class _ContantRightPageState extends State<ContantRightPage> {
setState(() {
_contacts = contacts;
if (_contacts.length > 0) {
_pageState = PageState.Success;
for (int i = 0; i < _contacts.length; i++) {
UserHistoryEntity item = UserHistoryEntity(
'',
'',
_contacts[i].displayName,
'',
_contacts[i].phones.first.value,
'');
item.pinyin =
item.pinyin = PinyinHelper.getPinyin(_contacts[i].displayName);
contantShowModel.contacts.add(item);
}
contantShowModel.contactsShow = contantShowModel.contacts;
contantShowModel.pageStateRight = PageState.Success;
} else {
_pageState = PageState.Empty;
contantShowModel.pageStateRight = PageState.Empty;
}
});
... ... @@ -200,30 +220,32 @@ class _ContantRightPageState extends State<ContantRightPage> {
@override
Widget build(BuildContext context) {
return _pageState != PageState.Success
? ExceptionPage(
pageState: _pageState,
callback: () async {
if (await checkContactPermission()) {
_openAddressBook();
} else {
goSetting = true;
openSetting();
}
},
emptyMsg: "暂时没有联系人哦",
emptyImg: "empty_search",
showMsg: "加载中,请稍后...",
)
: ListView.builder(
itemCount: _contacts?.length ?? 0,
contantShowModel = Provider.of<ContantShowModel>(context, listen: true);
return Consumer<ContantShowModel>(builder: (context, model, _) {
if (model.pageStateRight != PageState.Success) {
return ExceptionPage(
pageState: model.pageStateRight,
callback: () async {
if (await checkContactPermission()) {
_openAddressBook();
} else {
goSetting = true;
openSetting();
}
},
emptyMsg: "暂时没有联系人哦",
emptyImg: "empty_search",
showMsg: "加载中,请稍后...",
);
} else {
return ListView.builder(
itemCount: contantShowModel.contactsShow?.length ?? 0,
itemBuilder: (BuildContext context, int index) {
Contact c = _contacts?.elementAt(index);
UserHistoryEntity c = contantShowModel.contactsShow[index];
return InkWell(
onTap: () {
if (c.phones.first.value != null &&
c.phones.first.value != '') {
DialogUtil.goPhone(c.phones.first.value);
if (c.phone != null && c.phone != '') {
DialogUtil.goPhone(c.phone);
}
},
child: Column(
... ... @@ -257,18 +279,17 @@ class _ContantRightPageState extends State<ContantRightPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
c.displayName == null || c.displayName == ''
c.rname == null || c.rname == ''
? ''
: c.displayName,
: c.rname,
style: TextStyle(
color: MyColours.color_333333,
fontSize: ScreenUtil().setSp(32))),
VEmptyView(10),
Text(
c.phones.first.value == null ||
c.phones.first.value == ''
c.phone == null || c.phone == ''
? ''
: c.phones.first.value,
: c.phone,
style: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(30)))
... ... @@ -277,5 +298,7 @@ class _ContantRightPageState extends State<ContantRightPage> {
)
]));
});
}
});
}
}
... ...
import 'package:contacts_service/contacts_service.dart';
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/error.dart';
... ... @@ -6,12 +7,15 @@ import 'package:one_key/models/user_history_entity.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
import 'package:lpinyin/lpinyin.dart';
class ContantShowModel extends ChangeNotifier {
PageState pageStateLeft = PageState.Loading;
List<UserHistoryEntity> userHistorys = []; //历史录入
PageState pageStateRight = PageState.Loading;
List<UserHistoryEntity> userHistorys = []; //历史录入(总)
List<UserHistoryEntity> contacts = []; //手机通讯录(总)
List<UserHistoryEntity> userHistorysShow = []; //历史录入展示
List<UserHistoryEntity> contactsShow = []; //手机通讯录展示
//获取历史录入
getUserHistorys(BuildContext context, Map<String, String> params) async {
... ... @@ -42,9 +46,44 @@ class ContantShowModel extends ChangeNotifier {
if (userHistorys.length == 0) {
pageStateLeft = PageState.Empty;
} else {
for (int i = 0; i < userHistorys.length; i++) {
UserHistoryEntity item = userHistorys[i];
item.pinyin = PinyinHelper.getPinyin(item.rname);
userHistorys[i] = item;
}
userHistorysShow = userHistorys;
pageStateLeft = PageState.Success;
}
notifyListeners();
}
}
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 (userHistorysShow.length == 0) {
pageStateLeft = PageState.Empty;
}
if (contactsShow.length == 0) {
pageStateRight = PageState.Empty;
}
notifyListeners();
}
}
... ...
... ... @@ -47,6 +47,7 @@ import 'package:one_key/pages/webview/webview_page.dart';
import 'package:one_key/provider/base_info_provider.dart';
import 'package:one_key/provider/book_set_time_model.dart';
import 'package:one_key/provider/choose_table_model.dart';
import 'package:one_key/provider/contant_show_model.dart';
import 'package:one_key/provider/create_store_model.dart';
import 'package:one_key/provider/my_model.dart';
import 'package:one_key/provider/notebook_detail_change_model.dart';
... ... @@ -437,13 +438,14 @@ var myIntegralPageHandler = new Handler(
return ChangeNotifierProvider<MyModel>(
create: (_) => MyModel(), child: MyIntegralPage(sunModel: sunModel));
});
///我的联系人
var myContantPageHandler = new Handler(
handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
// IntegralSunModel sunModel = IntegralSunModel.fromJson(json
// .decode(FluroConvertUtils.fluroCnParamsDecode(params["sunModel"].first)));
// .decode(FluroConvertUtils.fluroCnParamsDecode(params["sunModel"].first)));
// String urlStr = FluroConvertUtils.fluroCnParamsDecode(params["urlStr"].first);
return ContactListPage();
return ChangeNotifierProvider<ContantShowModel>(
create: (_) => ContantShowModel(), child: ContactListPage());
});
... ...
... ... @@ -555,6 +555,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
lpinyin:
dependency: "direct main"
description:
name: lpinyin
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.3"
matcher:
dependency: transitive
description:
... ...
... ... @@ -116,7 +116,8 @@ dependencies:
dotted_border: ^1.0.7
scroll_to_index: ^2.0.0
#通讯录
#汉字转拼音
lpinyin: ^2.0.3
... ...