|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter_contacts/contact.dart';
|
|
|
import 'package:flutter_contacts/flutter_contacts.dart';
|
|
|
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
|
|
import 'package:project_telephony/utils/headers.dart';
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
import '../../base/base_style.dart';
|
|
|
import '../../model/mass_list_model.dart';
|
|
|
import '../../model/phone_num_model.dart';
|
|
|
import '../widget/plone_back_button.dart';
|
|
|
import '../widget/plone_bottom.dart';
|
|
|
|
|
|
class AddressBook extends StatefulWidget {
|
|
|
const AddressBook({Key? key}) : super(key: key);
|
|
|
|
|
|
@override
|
|
|
_AddressBookState createState() => _AddressBookState();
|
|
|
}
|
|
|
|
|
|
class _AddressBookState extends State<AddressBook> {
|
|
|
final EasyRefreshController _easyRefreshController = EasyRefreshController();
|
|
|
String phoneName = "";
|
|
|
List<MassListModel> massList = [];
|
|
|
List<PhoneNumModel> phoneList = [];
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
a();
|
|
|
super.initState();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void dispose() {
|
|
|
_easyRefreshController.dispose();
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
a() async {
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
List<String> numbers = [];
|
|
|
List<String>? nameList = [];
|
|
|
List<Contact>? contacts;
|
|
|
contacts = await FlutterContacts.getContacts();
|
|
|
for (var element in contacts) {
|
|
|
final full = await FlutterContacts.getContact(element.id);
|
|
|
if (full?.phones.length == 0) {
|
|
|
numbers.add('无');
|
|
|
} else {
|
|
|
nameList.add(full!.displayName);
|
|
|
numbers.add(full.phones.first.number);
|
|
|
phoneList.add(PhoneNumModel(
|
|
|
num: full.phones.first.number,
|
|
|
state: false,
|
|
|
time: 0,
|
|
|
name: full.displayName));
|
|
|
}
|
|
|
}
|
|
|
await prefs.setStringList("nameList", nameList );
|
|
|
prefs.setStringList("number", numbers);
|
|
|
print(phoneList);
|
|
|
massList.add(MassListModel(
|
|
|
state: false, list: phoneList, title: '未分组联系人', time: ''));
|
|
|
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return Scaffold(
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
appBar: AppBar(
|
|
|
elevation: 0,
|
|
|
title: Text(
|
|
|
'通讯录',
|
|
|
style: TextStyle(
|
|
|
fontSize: BaseStyle.fontSize34,
|
|
|
color: BaseStyle.color333333,
|
|
|
fontWeight: FontWeight.bold),
|
|
|
),
|
|
|
titleSpacing: 185.w,
|
|
|
actions: [
|
|
|
GestureDetector(
|
|
|
onTap: () {
|
|
|
showDialog(
|
|
|
context: context,
|
|
|
builder: (context) {
|
|
|
return CupertinoAlertDialog(
|
|
|
title: Text(
|
|
|
"添加分组",
|
|
|
style: TextStyle(
|
|
|
color: BaseStyle.color333333, fontSize: 34.sp),
|
|
|
),
|
|
|
content: Column(
|
|
|
children: [
|
|
|
Column(
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
children: [
|
|
|
CupertinoTextField(
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
horizontal: 24.w, vertical: 20.w),
|
|
|
decoration: BoxDecoration(
|
|
|
border: Border.all(color: Colors.white),
|
|
|
// borderRadius: BorderRadius.all(
|
|
|
// Radius.circular(4.w)
|
|
|
// ),
|
|
|
color: const Color(0xFFF9F9F9)),
|
|
|
placeholderStyle: TextStyle(
|
|
|
fontSize: 28.sp,
|
|
|
color: BaseStyle.color999999),
|
|
|
placeholder: "请输入分组名称(10个字以内)",
|
|
|
onChanged: (value) {
|
|
|
phoneName = value;
|
|
|
setState(() {});
|
|
|
},
|
|
|
),
|
|
|
|
|
|
82.hb,
|
|
|
// _getUpdate("爸爸", "123123123"),
|
|
|
PloneBottom(
|
|
|
blM: false,
|
|
|
border: true,
|
|
|
color1: const Color(0xFF1890FF),
|
|
|
color2: const Color(0xFF74BCFF),
|
|
|
onTap: () async {
|
|
|
DateTime now = DateTime.now();
|
|
|
String nowTime =
|
|
|
"${now.year}-${now.month}-${now.day} ${now.hour}:${now.minute}:${now.millisecond}";
|
|
|
massList.add(MassListModel(
|
|
|
state: false,
|
|
|
list: [],
|
|
|
title: phoneName,
|
|
|
time: nowTime));
|
|
|
// await
|
|
|
Navigator.pop(context);
|
|
|
_easyRefreshController.callRefresh();
|
|
|
},
|
|
|
text: "保存",
|
|
|
)
|
|
|
],
|
|
|
),
|
|
|
],
|
|
|
),
|
|
|
);
|
|
|
});
|
|
|
},
|
|
|
child: Padding(
|
|
|
padding: EdgeInsets.only(top: 40.w, right: 32.w),
|
|
|
child: SizedBox(
|
|
|
height: 28.w,
|
|
|
width: 120.w,
|
|
|
child: Text(
|
|
|
"添加分组",
|
|
|
style: TextStyle(
|
|
|
color: BaseStyle.color333333, fontSize: 28.sp),
|
|
|
),
|
|
|
)))
|
|
|
],
|
|
|
leading: const CloudBackButton(isSpecial: true),
|
|
|
backgroundColor: kForeGroundColor),
|
|
|
backgroundColor: Colors.white,
|
|
|
body: EasyRefresh(
|
|
|
firstRefresh: true,
|
|
|
header: MaterialHeader(),
|
|
|
controller: _easyRefreshController,
|
|
|
onRefresh: () async {
|
|
|
setState(() {});
|
|
|
},
|
|
|
child: ListView.builder(
|
|
|
itemBuilder: (context, index) {
|
|
|
return _getBox(massList[index], index, massList[index].list.length);
|
|
|
},
|
|
|
itemCount: massList.length,
|
|
|
),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
_getBox(MassListModel item, int index, int num) {
|
|
|
return GestureDetector(
|
|
|
child: CheckboxListTile(
|
|
|
onChanged: (bool? value) {
|
|
|
setState(() {
|
|
|
item.state = value!;
|
|
|
if (item.state) {
|
|
|
// phoneNum3.add({"phone":num,"remark":name});
|
|
|
// phoneNum3.add((phone: num, remark: name));
|
|
|
|
|
|
} else {
|
|
|
// phoneNum3.remove({"phone":num,"remark":name});
|
|
|
// phoneNum3.remove(ExcludePnModel(phone: num, remark: name)) ;
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
value: item.state,
|
|
|
title: Text(
|
|
|
"${item.title}($num)",
|
|
|
style: TextStyle(fontSize: 32.w, fontWeight: FontWeight.bold),
|
|
|
),
|
|
|
subtitle: Row(
|
|
|
children: [
|
|
|
Text(
|
|
|
index == 0 ? "本机通讯录" : item.time,
|
|
|
style: TextStyle(fontSize: 28.sp, color: BaseStyle.color999999),
|
|
|
),
|
|
|
// 30.wb,
|
|
|
// Text(
|
|
|
// item.name == null ? "" : item.name!,
|
|
|
// style: TextStyle(fontSize: 28.sp, color: BaseStyle.color999999),
|
|
|
// )
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
}
|