parent
e8a6602425
commit
339034f3c8
@ -0,0 +1,54 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
part 'phone_model.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: 0)
|
||||
class PhoneModel extends Equatable {
|
||||
@HiveField(0)
|
||||
String? title;
|
||||
@HiveField(1)
|
||||
String? time;
|
||||
@HiveField(2)
|
||||
bool? state;
|
||||
@HiveField(3)
|
||||
List<PhoneNum>? phoneList;
|
||||
|
||||
factory PhoneModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$PhoneModelFromJson(json);
|
||||
|
||||
PhoneModel({
|
||||
this.title,
|
||||
this.time,
|
||||
this.state,
|
||||
this.phoneList,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [title, time, state, phoneList];
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
@HiveType(typeId: 1)
|
||||
class PhoneNum extends Equatable {
|
||||
@HiveField(0)
|
||||
String? name;
|
||||
@HiveField(1)
|
||||
String? phone;
|
||||
@HiveField(2)
|
||||
bool? state;
|
||||
|
||||
factory PhoneNum.fromJson(Map<String, dynamic> json) =>
|
||||
_$PhoneNumFromJson(json);
|
||||
|
||||
PhoneNum({
|
||||
this.name,
|
||||
this.phone,
|
||||
this.state,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [name, phone, state];
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'phone_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class PhoneModelAdapter extends TypeAdapter<PhoneModel> {
|
||||
@override
|
||||
final int typeId = 0;
|
||||
|
||||
@override
|
||||
PhoneModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return PhoneModel(
|
||||
title: fields[0] as String?,
|
||||
time: fields[1] as String?,
|
||||
state: fields[2] as bool?,
|
||||
phoneList: (fields[3] as List?)?.cast<PhoneNum>(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, PhoneModel obj) {
|
||||
writer
|
||||
..writeByte(4)
|
||||
..writeByte(0)
|
||||
..write(obj.title)
|
||||
..writeByte(1)
|
||||
..write(obj.time)
|
||||
..writeByte(2)
|
||||
..write(obj.state)
|
||||
..writeByte(3)
|
||||
..write(obj.phoneList);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is PhoneModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
class PhoneNumAdapter extends TypeAdapter<PhoneNum> {
|
||||
@override
|
||||
final int typeId = 1;
|
||||
|
||||
@override
|
||||
PhoneNum read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return PhoneNum(
|
||||
name: fields[0] as String?,
|
||||
phone: fields[1] as String?,
|
||||
state: fields[2] as bool?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, PhoneNum obj) {
|
||||
writer
|
||||
..writeByte(3)
|
||||
..writeByte(0)
|
||||
..write(obj.name)
|
||||
..writeByte(1)
|
||||
..write(obj.phone)
|
||||
..writeByte(2)
|
||||
..write(obj.state);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is PhoneNumAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
PhoneModel _$PhoneModelFromJson(Map<String, dynamic> json) => PhoneModel(
|
||||
title: json['title'] as String?,
|
||||
time: json['time'] as String?,
|
||||
state: json['state'] as bool?,
|
||||
phoneList: (json['phoneList'] as List<dynamic>?)
|
||||
?.map((e) => PhoneNum.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
PhoneNum _$PhoneNumFromJson(Map<String, dynamic> json) => PhoneNum(
|
||||
name: json['name'] as String?,
|
||||
phone: json['phone'] as String?,
|
||||
state: json['state'] as bool?,
|
||||
);
|
@ -1,81 +0,0 @@
|
||||
|
||||
import 'package:hive/hive.dart';
|
||||
|
||||
|
||||
|
||||
@HiveType(typeId: 0)
|
||||
class PhoneNumberHive{
|
||||
@HiveField(0)
|
||||
int? id;
|
||||
@HiveField(1)
|
||||
String? title;
|
||||
@HiveField(2)
|
||||
String? time;
|
||||
@HiveField(3)
|
||||
bool? state;
|
||||
@HiveField(4)
|
||||
List<PhoneNumModel>? phoneList;
|
||||
|
||||
PhoneNumberHive({
|
||||
this.id,
|
||||
this.title,
|
||||
this.time,
|
||||
this.state,
|
||||
this.phoneList,
|
||||
});
|
||||
PhoneNumberHive.fromJson(Map<String,dynamic> json){
|
||||
id=json['id'];
|
||||
title=json['title'];
|
||||
time=json['time'];
|
||||
state=json['state'];
|
||||
if(json['phoneList'] !=null){
|
||||
phoneList=json['phoneList'].map((e) => PhoneNumModel.from(e)).toList();
|
||||
}else{
|
||||
phoneList=[];
|
||||
}
|
||||
}
|
||||
Map<String,dynamic> toJson(){
|
||||
final Map<String,dynamic> data= <String,dynamic>{};
|
||||
data['id'] =id;
|
||||
data['title']=title;
|
||||
data['time']=time;
|
||||
data['state']=state;
|
||||
if(phoneList!=null){
|
||||
data['phoneList']=phoneList!.map((e) => e.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@HiveType(typeId: 1)
|
||||
class PhoneNumModel{
|
||||
@HiveField(0)
|
||||
int? id;
|
||||
@HiveField(1)
|
||||
String? name;
|
||||
@HiveField(2)
|
||||
String? phone;
|
||||
@HiveField(3)
|
||||
bool? state;
|
||||
|
||||
PhoneNumModel({
|
||||
this.id,
|
||||
this.name,
|
||||
this.phone,
|
||||
this.state,
|
||||
});
|
||||
PhoneNumModel.from(Map<String,dynamic> json){
|
||||
id=json['id'];
|
||||
name=json['name'];
|
||||
phone=json['phone'];
|
||||
state=json['state'];
|
||||
}
|
||||
Map<String,dynamic> toJson(){
|
||||
final Map<String,dynamic> data=<String,dynamic>{};
|
||||
data["id"]=id;
|
||||
data['name']=name;
|
||||
data['phone']=phone;
|
||||
data['state']=state;
|
||||
return data;
|
||||
}
|
||||
}
|
@ -1,28 +1,44 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_contacts/flutter_contacts.dart';
|
||||
|
||||
import '../model/phone_num_model.dart';
|
||||
|
||||
import 'package:project_telephony/utils/hive_store.dart';
|
||||
|
||||
import '../model/hive/phone_model.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
//
|
||||
// await HiveStore.dataBox?.add(PhoneModel(name: full.displayName,phone:full.phones.first.number, state: false));
|
||||
// phoneList=HiveStore.dataBox?.get(PhoneModel());
|
||||
// HiveStore.dataBox?.add(PhoneNumberHive(state: false,phoneList: phoneList,title:"未分组联系人",time: ''));
|
||||
class PhoneNumProvider extends ChangeNotifier{
|
||||
final List<PhoneNumModel> _phoneNum=[PhoneNumModel(num: "",time: 0,name: "", state:false)];
|
||||
List<PhoneNumModel> get phoneNum=>_phoneNum;
|
||||
Future list(List<PhoneNumModel> phoneList) async{
|
||||
// await HiveStore.dataBox!.get();
|
||||
// final Iterable<CallLogEntry> entries = await CallLog.query();
|
||||
|
||||
// for (CallLogEntry entrie in entries) {
|
||||
// _phoneNum.add(PhoneNumModel(
|
||||
// num: entrie.number,
|
||||
// time: entrie.timestamp,
|
||||
// name: entrie.name,
|
||||
// state: false,
|
||||
// ));
|
||||
// // a.add(entrie.number);
|
||||
// }
|
||||
// final phoneList=_phoneNum.toSet();
|
||||
// final phoneList= HiveStore.dataBox?.get(phoneNum);
|
||||
return ;
|
||||
List<Contact>? contacts;
|
||||
final List<PhoneModel> _massList = [];
|
||||
List<PhoneNum> _phoneList = [];
|
||||
List<PhoneModel> get massList=>_massList;
|
||||
List<PhoneNum> get phoneList=>_phoneList;
|
||||
Future init() async{
|
||||
contacts = await FlutterContacts.getContacts();
|
||||
for (var element in contacts!) {
|
||||
final full = await FlutterContacts.getContact(element.id);
|
||||
_phoneList.add(PhoneNum(name: full?.displayName, phone: full?.phones.first.number,state: false));
|
||||
//
|
||||
// print(full?.displayName);
|
||||
// print(full?.phones.first.number);
|
||||
}
|
||||
await HiveStore.dataBox!.put("pl",_phoneList) ;
|
||||
_massList.add(PhoneModel(title:"未分组联系人",time: "本机通讯录",phoneList:HiveStore.dataBox!.get("pl"),state: false));
|
||||
HiveStore.dataBox?.put("ml",_massList) ;
|
||||
// print( "这是我的类型${HiveStore.dataBox?.get("ml").runtimeType}");
|
||||
|
||||
}
|
||||
Future upDate() async{
|
||||
_phoneList=await HiveStore.dataBox?.get("pl");
|
||||
|
||||
|
||||
}
|
||||
// Future
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyrefresh/easy_refresh.dart';
|
||||
import 'package:project_telephony/utils/headers.dart';
|
||||
import 'package:project_telephony/utils/hive_store.dart';
|
||||
|
||||
import '../../base/base_style.dart';
|
||||
import '../../model/hive/phone_model.dart';
|
||||
import '../../utils/user_tool.dart';
|
||||
import '../exclude/exclude_contacts_page.dart';
|
||||
import '../exclude/exclude_single_page.dart';
|
||||
import '../login/login_page.dart';
|
||||
import '../widget/plone_back_button.dart';
|
||||
|
||||
class CallListPage extends StatefulWidget {
|
||||
final String title;
|
||||
final List<PhoneNum> phoneNum;
|
||||
final int index;
|
||||
const CallListPage({Key? key, required this.title, required this.phoneNum,required this.index})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_CallListPageState createState() => _CallListPageState();
|
||||
}
|
||||
|
||||
class _CallListPageState extends State<CallListPage> {
|
||||
final EasyRefreshController _refreshController = EasyRefreshController();
|
||||
List<PhoneModel> messList = [];
|
||||
List<PhoneNum> numList = [];
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_refreshController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
if (UserTool.userProvider.isLogin) {
|
||||
if (UserTool.userProvider.userInfo.isVip != 1) {
|
||||
//service.isRunning() as bool;
|
||||
// endDate = DateUtil.formatDateMs(
|
||||
// UserTool.userProvider.userInfo.end * 1000,
|
||||
// format: DateFormats.y_mo_d);
|
||||
} else {
|
||||
Get.to(() => const LoginPage());
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
}
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
widget.title,
|
||||
style: TextStyle(
|
||||
fontSize: BaseStyle.fontSize34,
|
||||
color: BaseStyle.color333333,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
// titleSpacing: 150.w,
|
||||
leading: const CloudBackButton(
|
||||
isSpecial: true,
|
||||
isSpecials: false,
|
||||
),
|
||||
backgroundColor: kForeGroundColor),
|
||||
backgroundColor: Colors.white,
|
||||
body: EasyRefresh(
|
||||
firstRefresh: true,
|
||||
controller: _refreshController,
|
||||
header: MaterialHeader(),
|
||||
// footer: MaterialFooter(),
|
||||
onRefresh: () async {
|
||||
// await userProvider.updateUserInfo();
|
||||
|
||||
setState(() {});
|
||||
},
|
||||
child: widget.phoneNum.isEmpty
|
||||
? _getNullList()
|
||||
: _getNum(widget.phoneNum)
|
||||
|
||||
// ListView(
|
||||
// children: [findList.isEmpty ? _getNullList() : _getNum()],
|
||||
// )
|
||||
|
||||
),
|
||||
bottomNavigationBar: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
62.wb,
|
||||
_getBottom("号码添加", const Color(0xFF1890FF), () {
|
||||
Navigator.of(context)
|
||||
.push(
|
||||
MaterialPageRoute(builder: (_) => const ExcludeSinglePage( qf: true,)),
|
||||
)
|
||||
.then((value) => _refreshController.callRefresh());
|
||||
}, Colors.white, Colors.white, 2, const Color(0xFF1890FF), 58, 24),
|
||||
32.wb,
|
||||
_getBottom("通讯录中添加", Colors.white, () {
|
||||
Navigator.of(context)
|
||||
.push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ExcludeContactsPage(
|
||||
qf: true,
|
||||
index: widget.index,
|
||||
)),
|
||||
)
|
||||
.then((val) => _refreshController.callRefresh());
|
||||
}, const Color(0xFF74BCFF), const Color(0xFF1890FF), 0, Colors.white,
|
||||
96, 24),
|
||||
62.wb,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_getBottom(String text, Color textColor, VoidCallback ontap, Color color1,
|
||||
Color color2, int border, Color borderColor, int h, int v) {
|
||||
return GestureDetector(
|
||||
onTap: ontap,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: h.w, vertical: v.w),
|
||||
margin: EdgeInsets.only(bottom: 32.w),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8.w),
|
||||
gradient: LinearGradient(
|
||||
colors: [color1, color2],
|
||||
end: Alignment.centerRight,
|
||||
begin: Alignment.centerLeft),
|
||||
border: Border.all(width: border.w, color: borderColor)),
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 28.sp, color: textColor, fontWeight: FontWeight.w500),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_getNullList() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
490.hb,
|
||||
Image.asset(
|
||||
Assets.icons.nullphonelist.path,
|
||||
width: 240.w,
|
||||
height: 212.w,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
48.hb,
|
||||
Text(
|
||||
"这里是空的",
|
||||
style: TextStyle(
|
||||
color: const Color(0xFF999999),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 36.sp),
|
||||
),
|
||||
16.hb,
|
||||
Text(
|
||||
"还没有添加指定号码",
|
||||
style: TextStyle(color: const Color(0xFF999999), fontSize: 28.sp),
|
||||
),
|
||||
490.hb,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_getNum(List<PhoneNum> item) {
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.w),
|
||||
child: ListTile(
|
||||
onTap: () async {},
|
||||
title: Text(
|
||||
item[index].name ?? "",
|
||||
style: TextStyle(fontSize: 32.w, fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(
|
||||
item[index].phone ?? "",
|
||||
style: TextStyle(fontSize: 28.sp, color: BaseStyle.color999999),
|
||||
),
|
||||
trailing: TextButton(
|
||||
style: ButtonStyle(
|
||||
side: MaterialStateProperty.all(
|
||||
BorderSide(width: 2.w, color: const Color(0xFFE8E8E8)))),
|
||||
onPressed: () async {
|
||||
// print("123");
|
||||
messList =
|
||||
await HiveStore.dataBox?.get("ml").cast<PhoneModel>();
|
||||
// numList = HiveStore.dataBox?.get("pl").cast<PhoneNum>();
|
||||
// print(item[index]);
|
||||
// messList.removeWhere((element) => (element.phoneList)!.contains(item[index]));
|
||||
// numList.remove(item[index]);
|
||||
messList[widget.index].phoneList!.remove(item[index]);
|
||||
HiveStore.dataBox?.put("ml", messList);
|
||||
print(HiveStore.dataBox?.get("ml"));
|
||||
_refreshController.callRefresh();
|
||||
// print(HiveStore.dataBox?.get("pl"));
|
||||
},
|
||||
child: Text(
|
||||
"删除",
|
||||
style: TextStyle(fontSize: 28.sp, color: BaseStyle.color333333),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// CheckboxListTile(
|
||||
// onChanged: (bool? value) {
|
||||
// setState(() {
|
||||
// item[index].state = value!;
|
||||
// if (item[index].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[index].state,
|
||||
// title: Text(
|
||||
// item[index].name ?? "",
|
||||
// style: TextStyle(fontSize: 32.w, fontWeight: FontWeight.bold),
|
||||
// ),
|
||||
// subtitle: Row(
|
||||
// children: [
|
||||
// Text(
|
||||
// item[index].phone ?? "",
|
||||
// style: TextStyle(fontSize: 28.sp, color: BaseStyle.color999999),
|
||||
// ),
|
||||
// // 30.wb,
|
||||
// // Text(
|
||||
// // item.name == null ? "" : item.name!,
|
||||
// // style: TextStyle(fontSize: 28.sp, color: BaseStyle.color999999),
|
||||
// // )
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
},
|
||||
itemCount: widget.phoneNum.length,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue