群发功能增加

master
王亚玲 2 years ago
parent e8a6602425
commit 339034f3c8

@ -5,7 +5,6 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_background_service/flutter_background_service.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -13,11 +12,11 @@ import 'package:fluwx/fluwx.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:power_logger/power_logger.dart';
import 'package:project_telephony/providers/phone_num_provider.dart';
import 'package:project_telephony/providers/user_provider.dart';
import 'package:project_telephony/ui/home/call.dart';
import 'package:project_telephony/ui/loading.dart';
import 'package:project_telephony/ui/tab_navigator.dart';
@ -31,6 +30,7 @@ void main() async {
const buildType = String.fromEnvironment('BUILD_TYPE');
DeveloperUtil.setDev(!(buildType.contains('PRODUCT')));
WidgetsFlutterBinding.ensureInitialized();
await HiveStore.init();
// await initializeService();
// Workmanager().initialize(
// callbackDispatcher, // The top level function, aka callbackDispatcher

@ -8,7 +8,7 @@ part of 'ContentHive.dart';
class ContentHiveAdapter extends TypeAdapter<ContentHive> {
@override
final int typeId = 0;
final int typeId = 2;
@override
ContentHive read(BinaryReader reader) {

@ -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
}

@ -30,6 +30,8 @@ class UserProvider extends ChangeNotifier {
Future<bool> init() async {
if (HiveStore.appBox?.containsKey('token') ?? false) {
final token = HiveStore.appBox?.get('token') as String;
// UserTool.phoneNumProvider.init();
// print("重置");
_isLogin = true;
apiClient.setToken(token);
await updateUserInfo();
@ -55,6 +57,7 @@ class UserProvider extends ChangeNotifier {
await updateUserInfo();
prefs.setInt("numIndex", 0);
_viewLoading();
UserTool.phoneNumProvider.init();
// prefs.setStringList("dxText",["祝你万事顺心","欢迎你的来电,祝你生活愉快","感谢您的来电,我们会尽快处理",]);
updateConSms();
updateRefSms();
@ -70,6 +73,7 @@ class UserProvider extends ChangeNotifier {
apiClient.clearToken();
_isLogin = false;
await HiveStore.appBox?.delete('token');
HiveStore.dataBox?.delete("ml");
service.invoke("stopService");
}
@ -97,7 +101,7 @@ class UserProvider extends ChangeNotifier {
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
if (prefs.getBool('kg') ?? false) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
@ -120,7 +124,7 @@ class UserProvider extends ChangeNotifier {
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
if (prefs.getBool('kg') ?? false) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
@ -143,7 +147,7 @@ class UserProvider extends ChangeNotifier {
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
if (prefs.getBool('kg') ?? false) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
@ -166,7 +170,7 @@ class UserProvider extends ChangeNotifier {
? "${base.data['content']}"
: "${UserTool.userProvider.userInfo.tag}${base.data['content']}");
service.invoke("stopService");
if (prefs.getBool('kg')!) {
if (prefs.getBool('kg') ?? false) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
@ -183,9 +187,9 @@ class UserProvider extends ChangeNotifier {
var base = await apiClient.request(API.exclude.find);
if (base.code == 0) {
await prefs.remove('exclude');
await prefs.setStringList('exclude', base.data);
await prefs.setStringList('exclude', base.data ?? []);
service.invoke("stopService");
if (prefs.getBool('kg')!) {
if (prefs.getBool('kg') ?? false) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
@ -214,13 +218,11 @@ class UserProvider extends ChangeNotifier {
await prefs.setStringList("addressList", numbers);
service.invoke("stopService");
if (prefs.getBool('kg')!) {
if (prefs.getBool('kg') ?? false) {
Future.delayed(const Duration(seconds: 1), () async {
service.startService();
});
}
notifyListeners();
}
@ -241,7 +243,6 @@ class UserProvider extends ChangeNotifier {
// numbers.add(full!.phones.first.number);
}
}
await prefs.setStringList("nameList",nameList );
prefs.setStringList("number", numbers);
// print(contacts.length);

@ -1,19 +1,24 @@
import 'package:flustars/flustars.dart';
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/model/hive/phone_model.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:project_telephony/utils/hive_store.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';
import 'call_list_page.dart';
typedef NumList = Function(List<String> content);
class AddressBook extends StatefulWidget {
const AddressBook({Key? key}) : super(key: key);
final NumList number;
const AddressBook({Key? key, required this.number}) : super(key: key);
@override
_AddressBookState createState() => _AddressBookState();
@ -22,12 +27,20 @@ class AddressBook extends StatefulWidget {
class _AddressBookState extends State<AddressBook> {
final EasyRefreshController _easyRefreshController = EasyRefreshController();
String phoneName = "";
List<MassListModel> massList = [];
List<PhoneNumModel> phoneList = [];
List<PhoneModel> massList = [];
List<PhoneNum> phoneList = [];
List<String> NumList = [];
bool state=false;
@override
void initState() {
a();
// 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();
}
@ -37,179 +50,195 @@ class _AddressBookState extends State<AddressBook> {
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(() {});
},
),
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(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);
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(() {});
},
itemCount: massList.length,
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(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)) ;
}
});
_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());
},
value: item.state,
title: Text(
child: 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),
// )
],
),
),
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),
// )
],
),
);
}

@ -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,
);
}
}

@ -6,7 +6,6 @@ import 'package:project_telephony/ui/TextMe/text_template.dart';
import 'package:project_telephony/ui/widget/plone_bottom.dart';
import 'package:project_telephony/utils/headers.dart';
import 'package:project_telephony/utils/toast/cloud_toast.dart';
import 'package:telephony/telephony.dart';
import 'package:velocity_x/velocity_x.dart';
import '../widget/plone_back_button.dart';
@ -25,6 +24,7 @@ class _TextMePageState extends State<TextMePage> {
String signatureText = "";
late TextEditingController _controller;
late TextEditingController _phoneController;
List<String> list = [];
@override
void initState() {
@ -58,7 +58,8 @@ class _TextMePageState extends State<TextMePage> {
body: ListView(
children: [
_getBox('短信内容', "选择短信模版", () {
Get.to(() => TextTemplate(
Get.to(() =>
TextTemplate(
callback: (String content) {
_controller.text = content;
},
@ -66,7 +67,12 @@ class _TextMePageState extends State<TextMePage> {
}, "请输入短信内容...", _controller),
32.hb,
_getBox('收信号码', "通讯录中选择", () {
Get.to(() => const AddressBook());
Get.to(() =>
AddressBook(number: (List<String> content) {
for(int i=0;i<content.length;i++){
_phoneController.text +="${content[i]},";
}
},));
}, "请输入收信号码多个号码请用逗号隔开例如136xxxx6666132xxxx8888", _phoneController),
32.hb,
_getBox2(),
@ -83,15 +89,10 @@ class _TextMePageState extends State<TextMePage> {
print(_phoneController.text);
print(signatureText);
await sendSMS(
message:"$signatureText${_controller.text}",
recipients: [
"13395740386",
"13486828191",
// "18815060992",
// "18294841148"
],
message: "$signatureText${_controller.text}",
recipients: _phoneController.text.split(","),
sendDirect: true);
// print("asd${_phoneController.text.split(",")}");
// await telephony.sendSms(
// to: "13486828191;13395740386;18815060992;18294841148",
// message: "$signatureText${_controller.text}"
@ -104,8 +105,8 @@ class _TextMePageState extends State<TextMePage> {
_phoneController.text.isEmpty ||
signatureText.isEmpty,
opacity: _controller.text.isEmpty ||
_phoneController.text.isEmpty ||
signatureText.isEmpty
_phoneController.text.isEmpty ||
signatureText.isEmpty
? 0.4
: 1,
text: "发送",
@ -170,11 +171,12 @@ class _TextMePageState extends State<TextMePage> {
// }
// setState(() {});
// },
onSubmitted: (text){
onSubmitted: (text) {
if (title == "短信内容") {
_controller.text = text;
} else {
_phoneController.text = text;
}
setState(() {});
},

@ -73,7 +73,7 @@ class _TextTemplateState extends State<TextTemplate> {
footer: MaterialFooter(),
onRefresh: () async {
final prefs = await SharedPreferences.getInstance();
textList = prefs.getStringList("dxText")!;
textList = prefs.getStringList("dxText") ?? [];
textList.add("自定义短信模版");
setState(() {});
},

@ -4,16 +4,18 @@ import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:velocity_x/velocity_x.dart';
import '../../constants/api.dart';
import '../../model/exclude_phone_model.dart';
import '../../model/hive/phone_model.dart';
import '../../model/network/api_client.dart';
import '../../model/network/base_model.dart';
import '../../utils/hive_store.dart';
class ExcludeContactsPage extends StatefulWidget {
const ExcludeContactsPage({Key? key}) : super(key: key);
final bool qf;
final int index;
const ExcludeContactsPage({Key? key, this.qf = false,this.index=0}) : super(key: key);
@override
_ExcludeContactsPageState createState() => _ExcludeContactsPageState();
@ -25,6 +27,8 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
List<String> numbers1 = [];
List<bool> status = [];
var flag = true;
List<PhoneModel> messList = [];
List<PhoneNum> numList = [];
@override
void initState() {
@ -37,15 +41,15 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
contacts = await FlutterContacts.getContacts();
for (var element in contacts!) {
final full = await FlutterContacts.getContact(element.id);
if(full?.phones.length==0){
if (full?.phones.length == 0) {
numbers.add('');
}else{
} else {
numbers.add(full!.phones.first.number);
}
status.add(false);
}
// await prefs.setStringList("addressList", numbers);
print(contacts?.length);
// print(contacts?.length);
setState(() {});
}
@ -58,11 +62,9 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
flag = false;
return Container();
} else {
return ListView.builder(
itemCount: contacts!.length,
itemBuilder: (context, i) {
return ListTile(
title: Text(
contacts![i].displayName,
@ -106,15 +108,31 @@ class _ExcludeContactsPageState extends State<ExcludeContactsPage> {
if (status[i] == true) {
excludeList.add(
Exclude(phone: numbers[i], remark: contacts![i].displayName));
// numList.add(PhoneNum(phone: numbers[i],name: contacts![i].displayName,state: false));
}
}
if (status.contains(true)) {
BaseModel res = await apiClient
.request(API.exclude.add, data: {'exclude': excludeList});
if (res.code == 0) {
BotToast.showText(text: res.msg);
Get.back();
if (widget.qf) {
messList = await HiveStore.dataBox?.get("ml").cast<PhoneModel>();
// numList = HiveStore.dataBox?.get("pl").cast<PhoneNum>();
for (int i = 0; i < status.length; i++) {
if (status[i] == true) {
messList[widget.index].phoneList!.add(PhoneNum(phone: numbers[i],name: contacts![i].displayName,state: false));
}
}
HiveStore.dataBox?.put("ml", messList);
print(HiveStore.dataBox?.get("ml"));
Get.back();
// Get.back();
// _refreshController.callRefresh();
} else {
BaseModel res = await apiClient
.request(API.exclude.add, data: {'exclude': excludeList});
if (res.code == 0) {
BotToast.showText(text: res.msg);
Get.back();
Get.back();
}
}
} else {
BotToast.showText(text: "还未选中手机号");

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:project_telephony/model/hive/phone_model.dart';
import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart';
import 'package:velocity_x/velocity_x.dart';
@ -11,9 +12,12 @@ import '../../constants/api.dart';
import '../../model/exclude_phone_model.dart';
import '../../model/network/api_client.dart';
import '../../model/network/base_model.dart';
import '../../utils/hive_store.dart';
class ExcludeSinglePage extends StatefulWidget {
const ExcludeSinglePage({Key? key}) : super(key: key);
final bool qf;
final int index;
const ExcludeSinglePage({Key? key,this.qf=false,this.index=0}) : super(key: key);
@override
_ExcludeSinglePageState createState() => _ExcludeSinglePageState();
@ -47,6 +51,30 @@ class _ExcludeSinglePageState extends State<ExcludeSinglePage> {
if (_phoneController.text.isEmpty) {
BotToast.showText(text: "未输入手机号");
} else {
if(widget.qf){
List<PhoneModel> messList=[];
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?.add(
PhoneNum(
name: _nameController.text,
phone: _phoneController.text,
state: false,
)
);
// print(messList);
// messList.map((e) => e.phoneList!.add(PhoneNum(
// name: _nameController.text,
// phone:_phoneController.text ,
// state: false)));
HiveStore.dataBox?.put("ml", messList);
print(HiveStore.dataBox?.get("ml"));
// Get.back();
Get.back();
}else{
BaseModel res = await apiClient.request(
API.exclude.add,
data: {
@ -58,10 +86,10 @@ class _ExcludeSinglePageState extends State<ExcludeSinglePage> {
);
BotToast.showText(text: res.msg);
if (res.code == 0) {
Get.back();
// Get.back();
Get.back();
}
}
}}
},
isOpacity:
_phoneController.text.isNotEmpty || _nameController.text.isNotEmpty,

@ -60,8 +60,8 @@ void onStart(ServiceInstance service) async {
bool? callSw = prefs.getBool('callSwitch');
bool? idleSw = prefs.getBool('idleSwitch');
int? numberSet = prefs.getInt("numIndex") ?? 0;
List<String>? numberList = prefs.getStringList("addressList") ;
List<String>? noNumberList = prefs.getStringList("specified");
List<String>? numberList = prefs.getStringList("addressList") ??[] ;
List<String>? noNumberList = prefs.getStringList("specified") ??[];
print("号码设置$numberSet 通讯列表$numberList 指定不发送$noNumberList");
if (callState == "IDLE") {
if (flag != 0) {
@ -72,13 +72,13 @@ void onStart(ServiceInstance service) async {
// if()
switch (numberSet) {
case 0:
if (!(noNumberList!.contains(phoneNum))) {
if (!(noNumberList.contains(phoneNum))) {
if (flag > 0) {
print("来电拒接/未接");
// print("来电拒接/未接");
print("${phoneNum!}:${ref!}");
Telephony.backgroundInstance
.sendSms(to: phoneNum!, message: ref);
print("发送成功");
// print("发送成功");
} else if (flag == -1) {
print("来电接听");
print("${phoneNum!}:${con!}");
@ -110,8 +110,8 @@ void onStart(ServiceInstance service) async {
}
break;
case 1:
if ((numberList!.contains(phoneNum)) &&
!(noNumberList!.contains(phoneNum))) {
if ((numberList.contains(phoneNum)) &&
!(noNumberList.contains(phoneNum))) {
if (flag > 0) {
print("来电拒接/未接");
print("${phoneNum!}:${ref!}");
@ -149,8 +149,8 @@ void onStart(ServiceInstance service) async {
}
break;
case 2:
if (!(numberList!.contains(phoneNum)) &&
!(noNumberList!.contains(phoneNum))) {
if (!(numberList.contains(phoneNum)) &&
!(noNumberList.contains(phoneNum))) {
if (flag > 0) {
print("来电拒接/未接");
print("${phoneNum!}:${ref!}");

@ -6,7 +6,6 @@ import 'dart:async';
import 'package:project_telephony/utils/headers.dart';
import 'package:provider/provider.dart';
import '../constants/environment/environment.dart';
import '../providers/user_provider.dart';
import '../utils/hive_store.dart';
@ -19,10 +18,9 @@ class Loading extends StatefulWidget {
}
class _LoadingState extends State<Loading> {
Future initialAll() async {
await HiveStore.init();
}
// Future initialAll() async {
//
// }
@override
void initState() {
super.initState();
@ -36,7 +34,7 @@ class _LoadingState extends State<Loading> {
// environment: env == 'dev',
// );
Future.delayed(const Duration(milliseconds: 1000), () async {
await initialAll();
// await initialAll();
if (!await userProvider.init()) {
await Get.offAll(() => const TabNavigator());
// await Get.offAll(() => const LoginPage());

@ -54,7 +54,7 @@ class _LoginPageState extends State<LoginPage> {
_smsCodeFocusNode = FocusNode();
_phoneController = TextEditingController();
_smsCodeController = TextEditingController();
final userProvider = Provider.of<UserProvider>(context, listen: false);
// final userProvider = Provider.of<UserProvider>(context, listen: false);
var env = const String.fromEnvironment('ENV', defaultValue: 'dev');
if (kDebugMode) {
print('env :$env');

@ -30,10 +30,10 @@ class _TabNavigatorState extends State<TabNavigator>
void initState() {
super.initState();
//
Future.delayed(const Duration(milliseconds: 0), () async {
//Hive.initFlutter;
await HiveStore.init();
});
// Future.delayed(const Duration(milliseconds: 0), () async {
// //Hive.initFlutter;
// await HiveStore.init();
// });
_pages = [const HomePage(), const TextMePage(),const UserPage()];
_tabController = TabController(
length: _pages.length, vsync: this, initialIndex: widget.index ?? 0);

@ -28,8 +28,6 @@ import '../home/call.dart';
import '../widget/appdialog.dart';
import 'content_details_page.dart';
class UserPage extends StatefulWidget {
const UserPage({Key? key}) : super(key: key);
@ -65,6 +63,7 @@ class _UserPageState extends State<UserPage> {
@override
void initState() {
super.initState();
// showDialog(context: context, builder: (context){
// return const AppDialog();
// });
@ -91,6 +90,25 @@ class _UserPageState extends State<UserPage> {
// }
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
Future.delayed(const Duration(seconds: 1)).then((value) {
if (UserTool.userProvider.userInfo.isTrial != 1) {
showDialog(
context: context,
builder: (context) {
return const AppDialog();
}).then((value) => getRe());
}
});
}
getRe() async {
UserTool.userProvider.updateUserInfo();
_easyRefreshController.callRefresh();
}
// getRes() async{
// var res=await apiClient.request(API.app.trialVip);
// if(res.code==0){
@ -122,16 +140,8 @@ class _UserPageState extends State<UserPage> {
_getRequests();
// await UserTool.userProvider.updateUserInfo();
if (UserTool.userProvider.isLogin) {
// var res=await apiClient.request(API.app.trialVip);
//01
if (UserTool.userProvider.userInfo.isTrial != 1) {
showDialog(
context: context,
builder: (context) {
return const AppDialog();
}).then((value) => _easyRefreshController.callRefresh());
}
// print(UserTool.userProvider.userInfo.end * 1000);
// print(DateTime.now().millisecondsSinceEpoch);
if (UserTool.userProvider.userInfo.isVip != 1) {
@ -147,7 +157,7 @@ class _UserPageState extends State<UserPage> {
// format: DateFormats.y_mo_d);
} else {
vle = false;
Get.to(()=>const LoginPage());
Get.to(() => const LoginPage());
}
setState(() {});
},
@ -164,7 +174,7 @@ class _UserPageState extends State<UserPage> {
_getSwitch(Assets.icons.sms.path, "短信标签", false),
_getSwitch(Assets.icons.card.path, "卡密兑换", false),
// const Spacer(),
100.hb,
100.hb,
UserTool.userProvider.isLogin
? PloneBottom(
border: false,
@ -444,6 +454,7 @@ class _UserPageState extends State<UserPage> {
// service.invoke("stopService");
// });
service.invoke("stopService");
///
// exit(0);
// UserTool.userProvider.setKg(vle);
@ -488,22 +499,19 @@ class _UserPageState extends State<UserPage> {
case "卡密兑换":
Navigator.of(context)
.push(
MaterialPageRoute(builder: (_) => const UserCardPage()),
)
MaterialPageRoute(builder: (_) => const UserCardPage()),
)
.then((val) => _getRequests()
// _easyRefreshController.callRefresh()
// _easyRefreshController.callRefresh()
);
);
break;
default:
break;
}
}
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 32.w),
child: ListTile(

@ -74,8 +74,8 @@ _getBotton(String bContent, context) {
var res = await apiClient.request(API.app.trialVip);
if (res.code == 0) {
CloudToast.show(res.msg);
UserTool.userProvider.updateUserInfo();
Navigator.pop(context);
Get.back();
// Navigator.pop(context);
} else {
CloudToast.show(res.msg);

@ -48,6 +48,7 @@ class _ScaffoldThemeWidgetState extends State<ScaffoldThemeWidget> {
resizeToAvoidBottomInset: false,
appBar: AppBar(
elevation: 0,
centerTitle: true,
title: Text(
widget.title,
style: TextStyle(
@ -55,7 +56,7 @@ class _ScaffoldThemeWidgetState extends State<ScaffoldThemeWidget> {
color: BaseStyle.color333333,
fontWeight: FontWeight.bold),
),
titleSpacing: widget.wid.w,
// titleSpacing: widget.wid.w,
leading: const CloudBackButton(isSpecial: true),
backgroundColor: kForeGroundColor),
backgroundColor: Colors.white,

@ -2,7 +2,9 @@ import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
import '../model/hive/phone_number_hive.dart';
import '../model/hive/ContentHive.dart';
import '../model/hive/phone_model.dart';
class HiveStore {
static Box? _appBox;
@ -20,7 +22,9 @@ class HiveStore {
var dir = await getApplicationDocumentsDirectory();
Hive.init(dir.path);
// Hive.registerAdapter(MyObjectAdapter());
// Hive.registerAdapter(PhoneNumberHive()); //HiveTypeId:0
Hive.registerAdapter(PhoneModelAdapter()); //HiveTypeId:0
Hive.registerAdapter(PhoneNumAdapter()); //HiveTypeId:1
Hive.registerAdapter(ContentHiveAdapter());//HiveTypeId:2
_appBox = await Hive.openBox('app');
_userBox = await Hive.openBox('userBox');
_dataBox = await Hive.openBox('dataBox');

@ -7,10 +7,12 @@ import 'headers.dart';
class UserTool {
static UserProvider userProvider =
Provider.of<UserProvider>(Get.context!, listen: false);
// static PhoneProvider phoneProvider=Provider.of<PhoneProvider>(Get.context!, listen: false);
}
class PhoneTool {
static PhoneNumProvider phoneNumProvider =
Provider.of<PhoneNumProvider>(Get.context!, listen: false);
Provider.of<PhoneNumProvider>(Get.context!, listen: false);
// static PhoneProvider phoneProvider=Provider.of<PhoneProvider>(Get.context!, listen: false);
}
//
// class PhoneTool {
// static PhoneNumProvider phoneNumProvider =
// Provider.of<PhoneNumProvider>(Get.context!, listen: false);
// }

Loading…
Cancel
Save