|
...
|
...
|
@@ -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> { |
|
|
|
)
|
|
|
|
]));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|