You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
9.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:project_telephony/model/hive/phone_model.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:project_telephony/utils/hive_store.dart';
import '../../base/base_style.dart';
import '../widget/plone_back_button.dart';
import '../widget/plone_bottom.dart';
import 'call_list_page.dart';
typedef NumList = Function(List<String> content);
class AddressBook extends StatefulWidget {
final NumList number;
const AddressBook({Key? key, required this.number}) : super(key: key);
@override
_AddressBookState createState() => _AddressBookState();
}
class _AddressBookState extends State<AddressBook> {
final EasyRefreshController _easyRefreshController = EasyRefreshController();
String phoneName = "";
List<PhoneModel> massList = [];
List<PhoneNum> phoneList = [];
List<String> NumList = [];
bool state=false;
@override
void initState() {
// print("这是我的第二个类型${massList.runtimeType}");
// print(HiveStore.dataBox?.get("ml"));
massList = HiveStore.dataBox?.get("ml").cast<PhoneModel>();
// UserTool.phoneNumProvider.init();
// massList=HiveStore.dataBox?.get("ml").cast<PhoneModel>();
// List<dynamic> list<PhoneModel>
// massList= HiveStore.dataBox?.get("ml");
super.initState();
}
@override
void dispose() {
_easyRefreshController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
elevation: 0,
centerTitle: true,
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(PhoneModel(
time: nowTime,
phoneList: [],
state: false,
title: phoneName));
await HiveStore.dataBox
?.put("ml", massList);
// massList.add(MassListModel(
// state: false,
// list: [],
// title: phoneName,
// time: nowTime));
// // await
// Navigator.pop(context);
Get.back();
_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 {
// UserTool.phoneNumProvider.init();
// massList=HiveStore.dataBox?.get("ml");
// massList=HiveStore.dataBox?.get("ml").cast<PhoneModel>();
// massList=HiveStore.dataBox?.get("ml").cast<List<PhoneModel>>();
setState(() {});
},
child: ListView.builder(
itemBuilder: (context, index) {
return _getBox(
massList[index], index, massList[index].phoneList!.length);
},
itemCount: massList.length,
),
),
bottomNavigationBar: Padding(
padding: EdgeInsets.only(bottom: 24.w),
child: PloneBottom(
onTap: () {
widget.number(NumList);
Get.back();
},
// border: state,
opacity: 1,
text: "确定",
),
));
}
_getBox(PhoneModel item, int index, int num) {
return CheckboxListTile(
onChanged: (bool? value) {
setState(() {
item.state = value!;
state=value;
if (item.state!) {
item.phoneList?.forEach((element) {
NumList.add(element.phone ?? "");
});
// item.phoneList!.map((e) => NumList.add(e.phone ??""));
} else {
item.phoneList?.forEach((element) {
NumList.remove(element.phone ?? "");
});
// item.phoneList!.map((e) => NumList.remove(e.phone ??""));
// phoneNum3.remove({"phone":num,"remark":name});
// phoneNum3.remove(ExcludePnModel(phone: num, remark: name)) ;
}
});
},
value: item.state,
title: GestureDetector(
onTap: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) =>
CallListPage(
phoneNum: item.phoneList ?? [],
title: item.title ?? "",
index: index,
))).then((value) => _easyRefreshController.callRefresh());
print(index);
},
child: Text(
"${item.title}($num)",
style: TextStyle(fontSize: 32.w, fontWeight: FontWeight.bold),
),
),
subtitle: Row(
children: [
Text(
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),
// )
],
),
);
}
}