From e8a66024257c8ef108d52fac4356f2e27507c924 Mon Sep 17 00:00:00 2001 From: wylyl22 <2373073266@qq.com> Date: Tue, 20 Sep 2022 10:26:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/model/hive/phone_number_hive.dart | 81 +++++++++++++++++++++++++++ lib/providers/user_provider.dart | 2 - lib/ui/TextMe/text_me_page.dart | 38 ++++++++----- lib/ui/home/call.dart | 3 +- lib/utils/hive_store.dart | 5 +- pubspec.yaml | 2 + 6 files changed, 112 insertions(+), 19 deletions(-) create mode 100644 lib/model/hive/phone_number_hive.dart diff --git a/lib/model/hive/phone_number_hive.dart b/lib/model/hive/phone_number_hive.dart new file mode 100644 index 0000000..da42aed --- /dev/null +++ b/lib/model/hive/phone_number_hive.dart @@ -0,0 +1,81 @@ + +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? phoneList; + + PhoneNumberHive({ + this.id, + this.title, + this.time, + this.state, + this.phoneList, + }); + PhoneNumberHive.fromJson(Map 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 toJson(){ + final Map data= {}; + 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 json){ + id=json['id']; + name=json['name']; + phone=json['phone']; + state=json['state']; + } + Map toJson(){ + final Map data={}; + data["id"]=id; + data['name']=name; + data['phone']=phone; + data['state']=state; + return data; + } +} \ No newline at end of file diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart index 4754978..47b41d3 100644 --- a/lib/providers/user_provider.dart +++ b/lib/providers/user_provider.dart @@ -6,10 +6,8 @@ import 'package:project_telephony/utils/user_tool.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../constants/api.dart'; -import '../model/exclude_phone_model.dart'; import '../model/login_info_model.dart'; import '../model/network/api_client.dart'; -import '../model/phone_num_model.dart'; import '../model/user_info_model.dart'; import '../ui/home/set/func/exclude_contacts_func.dart'; import '../utils/hive_store.dart'; diff --git a/lib/ui/TextMe/text_me_page.dart b/lib/ui/TextMe/text_me_page.dart index 86aac51..e9a91e3 100644 --- a/lib/ui/TextMe/text_me_page.dart +++ b/lib/ui/TextMe/text_me_page.dart @@ -73,7 +73,7 @@ class _TextMePageState extends State { 64.hb, PloneBottom( onTap: () async { - final Telephony telephony = Telephony.instance; + // final Telephony telephony = Telephony.instance; if (_controller.text.isEmpty && _phoneController.text.isEmpty && signatureText.isEmpty) { @@ -82,20 +82,20 @@ class _TextMePageState extends State { print(_controller.text); print(_phoneController.text); print(signatureText); - // await sendSMS( - // message: _controller.text, - // recipients: [ - // "13395740386", - // "13486828191", - // "18815060992", - // "18294841148" - // ], - // sendDirect: true); + await sendSMS( + message:"【$signatureText】${_controller.text}", + recipients: [ + "13395740386", + "13486828191", + // "18815060992", + // "18294841148" + ], + sendDirect: true); - await telephony.sendSms( - to: "13486828191,13395740386;18815060992;18294841148", - message: "【$signatureText】${_controller.text}" - ); + // await telephony.sendSms( + // to: "13486828191;13395740386;18815060992;18294841148", + // message: "【$signatureText】${_controller.text}" + // ); CloudToast.show("发送成功"); // Telephony.sendSms(to: phoneNum!, message: idle); } @@ -162,7 +162,15 @@ class _TextMePageState extends State { // focusNode: verifyNode, maxLines: 100, keyboardType: TextInputType.text, - onChanged: (text) { + // onChanged: (text) { + // if (title == "短信内容") { + // _controller.text = text; + // } else { + // _phoneController.text = text; + // } + // setState(() {}); + // }, + onSubmitted: (text){ if (title == "短信内容") { _controller.text = text; } else { diff --git a/lib/ui/home/call.dart b/lib/ui/home/call.dart index c8c6f4d..868020c 100644 --- a/lib/ui/home/call.dart +++ b/lib/ui/home/call.dart @@ -59,7 +59,7 @@ void onStart(ServiceInstance service) async { String? idle = prefs.getString('idleSms'); bool? callSw = prefs.getBool('callSwitch'); bool? idleSw = prefs.getBool('idleSwitch'); - int? numberSet = prefs.getInt("numIndex"); + int? numberSet = prefs.getInt("numIndex") ?? 0; List? numberList = prefs.getStringList("addressList") ; List? noNumberList = prefs.getStringList("specified"); print("号码设置$numberSet 通讯列表$numberList 指定不发送$noNumberList"); @@ -69,6 +69,7 @@ void onStart(ServiceInstance service) async { phoneNum = entry.first.number; callRecords = entry.first.duration; print(phoneNum); + // if() switch (numberSet) { case 0: if (!(noNumberList!.contains(phoneNum))) { diff --git a/lib/utils/hive_store.dart b/lib/utils/hive_store.dart index 8855591..75f1058 100644 --- a/lib/utils/hive_store.dart +++ b/lib/utils/hive_store.dart @@ -2,6 +2,8 @@ import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; import 'package:path_provider/path_provider.dart'; +import '../model/hive/phone_number_hive.dart'; + class HiveStore { static Box? _appBox; @@ -17,7 +19,8 @@ class HiveStore { if (!kIsWeb) { var dir = await getApplicationDocumentsDirectory(); Hive.init(dir.path); - // Hive.registerAdapter(()); //HiveTypeId:0 + // Hive.registerAdapter(MyObjectAdapter()); + // Hive.registerAdapter(PhoneNumberHive()); //HiveTypeId:0 _appBox = await Hive.openBox('app'); _userBox = await Hive.openBox('userBox'); _dataBox = await Hive.openBox('dataBox'); diff --git a/pubspec.yaml b/pubspec.yaml index 7444237..b3ecc48 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -99,6 +99,8 @@ dependencies: common_utils: ^2.1.0 # 群发号码 flutter_sms: ^2.3.3 +## 生成适配器 +# hive_generator: ^1.1.3 # # jdk # jverify: ^2.2.5 ## pub 集成