From f5d14e106031bbd55cd7d5cd5c60330834ef3fc2 Mon Sep 17 00:00:00 2001 From: datang Date: Fri, 9 Sep 2022 18:18:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/src/main/AndroidManifest.xml | 2 + lib/ui/exclude/exclude_contacts_page.dart | 85 +++++++++++++++- lib/ui/exclude/exclude_single_page.dart | 68 +++++++++++++ lib/ui/home/set/specify_phone_page.dart | 115 +++++++++++----------- lib/ui/user/privacy_rights_page.dart | 7 +- lib/ui/widget/scaffold_theme_widget.dart | 20 ++-- pubspec.lock | 7 ++ pubspec.yaml | 2 + 8 files changed, 236 insertions(+), 70 deletions(-) create mode 100644 lib/ui/exclude/exclude_single_page.dart diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3add551..9620d25 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -42,6 +42,8 @@ + + diff --git a/lib/ui/exclude/exclude_contacts_page.dart b/lib/ui/exclude/exclude_contacts_page.dart index ddd053a..f72f850 100644 --- a/lib/ui/exclude/exclude_contacts_page.dart +++ b/lib/ui/exclude/exclude_contacts_page.dart @@ -1,4 +1,11 @@ +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_contacts/flutter_contacts.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:get/get_core/src/get_main.dart'; +import 'package:get/get_utils/get_utils.dart'; import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart'; class ExcludeContactsPage extends StatefulWidget { @@ -9,13 +16,87 @@ class ExcludeContactsPage extends StatefulWidget { } class _ExcludeContactsPageState extends State { + late List contacts; + List numbers = []; + List status = []; + var flag = true; + + @override + void initState() { + super.initState(); + _incrementCounter(); + } + + Future _incrementCounter() async { + contacts = await FlutterContacts.getContacts(); + for (var element in contacts) { + final full = await FlutterContacts.getContact(element.id); + numbers.add(full!.phones.first.number); + status.add(false); + } + setState(() {}); + } + @override Widget build(BuildContext context) { + var profileBuilder = FutureBuilder( + future: _incrementCounter(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.waiting && flag) { + flag = false; + return Container(); + } else { + return ListView.builder( + itemCount: contacts.length, + itemBuilder: (context, i) => ListTile( + title: Text( + contacts[i].displayName, + style: TextStyle( + fontSize: 32.sp, + fontWeight: FontWeight.w600, + ), + ), + subtitle: Text( + numbers[i], + style: TextStyle( + fontSize: 28.sp, + fontWeight: FontWeight.w300, + ), + ), + trailing: Checkbox( + value: status[i], + // 改变后的事件 + onChanged: (value) { + setState(() { + status[i] = !status[i]; + }); + }, + // 选中后的颜色 + activeColor: Colors.blue, + // 选中后对号的颜色 + checkColor: Colors.white, + ), + ).paddingOnly(left: 20.w), + ); + } + }, + ); + return ScaffoldThemeWidget( title: "从通讯录添加", bottom: "添加", - onTap: () { }, - child: Container(), + onTap: () { + if(status.contains(true)){ + // BotToast.showText(text: "有"); + + Get.back(); + }else{ + BotToast.showText(text: "还未选中手机号"); + } + }, + isOpacity: status.contains(true), + isBorder: true, + child: profileBuilder, ); } } diff --git a/lib/ui/exclude/exclude_single_page.dart b/lib/ui/exclude/exclude_single_page.dart new file mode 100644 index 0000000..f47907b --- /dev/null +++ b/lib/ui/exclude/exclude_single_page.dart @@ -0,0 +1,68 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:project_telephony/ui/widget/scaffold_theme_widget.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class ExcludeSinglePage extends StatefulWidget { + const ExcludeSinglePage({Key? key}) : super(key: key); + + @override + _ExcludeSinglePageState createState() => _ExcludeSinglePageState(); +} + +class _ExcludeSinglePageState extends State { + @override + Widget build(BuildContext context) { + return ScaffoldThemeWidget( + title: '添加单个或批量号码', + bottom: "添加", + onTap: () {}, + child: Container( + padding: EdgeInsets.only(top: 25.h, left: 50.w, right: 50.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + addNumber("号码", "请输入号码"), + 15.heightBox, + addNumber("名称", "请输入名称"), + 15.heightBox, + RichText( + text: const TextSpan( + children: [ + TextSpan(text: "使用说明:"), + TextSpan(text: "如输入000*,可屏蔽所有000开头的号码") + ], + ), + ), + ], + ), + ), + ); + } + + addNumber(String title, content) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + title, + style: const TextStyle( + fontSize: 18, + color: Colors.black38, + fontWeight: FontWeight.w600, + ), + ), + 15.heightBox, + TextField( + decoration: InputDecoration( + hintText: content, + border: const OutlineInputBorder( + ), + ), + ), + ], + ); + } +} diff --git a/lib/ui/home/set/specify_phone_page.dart b/lib/ui/home/set/specify_phone_page.dart index 3ec0df1..b12a1eb 100644 --- a/lib/ui/home/set/specify_phone_page.dart +++ b/lib/ui/home/set/specify_phone_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; import 'package:project_telephony/ui/exclude/exclude_contacts_page.dart'; +import 'package:project_telephony/ui/exclude/exclude_single_page.dart'; import 'package:project_telephony/ui/home/home_page.dart'; import 'package:project_telephony/ui/home/set/phone_num_list/call_records_list.dart'; import 'package:project_telephony/utils/headers.dart'; @@ -29,76 +30,78 @@ class _SpecifyPhonePageState extends State { @override Widget build(BuildContext context) { - return ScaffoldThemeWidget(title: "发送号码设置", bottom: '添加', onTap: () { - showModalBottomSheet( - builder: (BuildContext context) { - return Container( - width: double.infinity, - height: 750.w, - padding: EdgeInsets.symmetric(horizontal: 32.w), - child: Column( - children: [ - 48.hb, - Text( - "添加号码", - style: TextStyle( - fontSize: 34.w, - fontWeight: FontWeight.bold), - ), - Expanded( - child: ListView( + return ScaffoldThemeWidget( + title: "发送号码设置", + bottom: '添加', + onTap: () { + showModalBottomSheet( + builder: (BuildContext context) { + return Container( + width: double.infinity, + height: 750.w, + padding: EdgeInsets.symmetric(horizontal: 32.w), + child: Column( + children: [ + 48.hb, + Text( + "添加号码", + style: TextStyle( + fontSize: 34.w, fontWeight: FontWeight.bold), + ), + Expanded( + child: ListView( children: [ _getAddPhone("通话记录添加", "通过本机通话记录添加号码", () { - Get.to(() => ScaffoldThemeWidget( + Get.to(() => ScaffoldThemeWidget( bottom: '添加', title: '从通话记录添加', isBorder: true, isOpacity: false, - onTap: () { }, - child: const CallRecordsList() - )); + onTap: () {}, + child: const CallRecordsList())); }), _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () { Get.to(() => (const ExcludeContactsPage())); }), - _getAddPhone( - "添加单个或批量号码", "通过输入号码段添加批量号码", () {}), + _getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () { + Get.to(() => (const ExcludeSinglePage())); + }), ], )), - PloneBottom( - onTap: () { - Navigator.pop(context); - }, - hPadding: 32, - border: true, - textColor: const Color(0xFF1890FF), - color2: const Color(0xFFF9F9F9), - color1: const Color(0xFFF9F9F9), - text: "取消", + PloneBottom( + onTap: () { + Navigator.pop(context); + }, + hPadding: 32, + border: true, + textColor: const Color(0xFF1890FF), + color2: const Color(0xFFF9F9F9), + color1: const Color(0xFFF9F9F9), + text: "取消", + ), + 32.hb + ], ), - 32.hb - ], - ), - ); - }, - context: context); - }, - child: EasyRefresh( - firstRefresh: true, - controller: _refreshController, - header: MaterialHeader(), - // footer: MaterialFooter(), - onRefresh: () async { - // await userProvider.updateUserInfo(); + ); + }, + context: context); + }, + child: EasyRefresh( + firstRefresh: true, + controller: _refreshController, + header: MaterialHeader(), + // footer: MaterialFooter(), + onRefresh: () async { + // await userProvider.updateUserInfo(); - setState(() {}); - }, - child: ListView( - children: [ - _getNullList(), - - ], - )),); + setState(() {}); + }, + child: ListView( + children: [ + _getNullList(), + ], + )), + ); // PloneBottom( // onTap: () { // showModalBottomSheet( diff --git a/lib/ui/user/privacy_rights_page.dart b/lib/ui/user/privacy_rights_page.dart index 461f9b8..3bdec92 100644 --- a/lib/ui/user/privacy_rights_page.dart +++ b/lib/ui/user/privacy_rights_page.dart @@ -1,4 +1,3 @@ - import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; @@ -8,8 +7,6 @@ import 'package:project_telephony/ui/widget/plone_back_button.dart'; import 'package:project_telephony/utils/headers.dart'; import 'package:url_launcher/url_launcher.dart'; - - class PrivacyRightsPage extends StatefulWidget { final String name; @@ -30,6 +27,7 @@ final Uri _url = Uri.parse('https://www.dxbs.vip//explain.html'); bool sms = false; bool plone = false; bool callLog = false; +bool contacts = false; @override class _PrivacyRightsPageState extends State { @@ -45,6 +43,7 @@ class _PrivacyRightsPageState extends State { sms = await Permission.sms.request().isGranted; plone = await Permission.phone.request().isGranted; callLog = await Permission.callLog.request().isGranted; + contacts = await Permission.contacts.request().isGranted; setState(() {}); } @@ -69,6 +68,7 @@ class _PrivacyRightsPageState extends State { _getRights("获取设备来电状态", "用于获取来电状态", plone), _getRights("获取设备短信权限", "用于发送短信", sms), _getRights("获取设备通话记录", "用于获取来电", callLog), + _getRights("获取设备通讯录", "用于插入排除手机号", contacts), ], ), bottomNavigationBar: GestureDetector( @@ -121,6 +121,7 @@ class _PrivacyRightsPageState extends State { onTap: () async { if (!state) { openAppSettings(); + setState(() {}); } // if(!(sms && plone)){ // // print(sms); diff --git a/lib/ui/widget/scaffold_theme_widget.dart b/lib/ui/widget/scaffold_theme_widget.dart index ace58e1..a6a8e7d 100644 --- a/lib/ui/widget/scaffold_theme_widget.dart +++ b/lib/ui/widget/scaffold_theme_widget.dart @@ -23,20 +23,22 @@ class ScaffoldThemeWidget extends StatefulWidget { final bool isBorder; final bool isOpacity; final VoidCallback onTap; - const ScaffoldThemeWidget( - {Key? key, required this.title, required this.child, required this.bottom, this.isBorder = false, this.isOpacity = true,required this.onTap - }) - : super(key: key); + + const ScaffoldThemeWidget({ + Key? key, + required this.title, + required this.child, + required this.bottom, + this.isBorder = false, + this.isOpacity = true, + required this.onTap, + }) : super(key: key); @override _ScaffoldThemeWidgetState createState() => _ScaffoldThemeWidgetState(); } class _ScaffoldThemeWidgetState extends State { - @override - void initState() { - super.initState(); - } // final userProvider = Provider.of(Get.context!, listen: false); @override @@ -59,7 +61,7 @@ class _ScaffoldThemeWidgetState extends State { body: widget.child, bottomNavigationBar: PloneBottom( onTap: widget.onTap, - border:widget.isBorder, + border: widget.isBorder, opacity: widget.isOpacity ? 1 : 0.4, text: widget.bottom, ).paddingOnly(bottom: 30.w), diff --git a/pubspec.lock b/pubspec.lock index 35ae3bc..55ec041 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -360,6 +360,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.0" + flutter_contacts: + dependency: "direct main" + description: + name: flutter_contacts + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.5" flutter_easyrefresh: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index a050301..16d4c30 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -93,6 +93,8 @@ dependencies: url_launcher: ^6.1.5 #tabBar样式切换 tab_indicator_styler: ^2.0.0 +#手机通讯录 + flutter_contacts: ^1.1.5 # # jdk # jverify: ^2.2.5