From 300caf7f27d803fe998c71f7821b641a9e2c368e Mon Sep 17 00:00:00 2001 From: datang Date: Tue, 13 Sep 2022 10:30:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E4=B8=AA?= =?UTF-8?q?=E5=8F=B7=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/exclude/exclude_single_page.dart | 77 ++++++++++++++++--- lib/ui/login/login_page.dart | 97 +++++++++++++----------- lib/ui/widget/scaffold_theme_widget.dart | 2 +- 3 files changed, 121 insertions(+), 55 deletions(-) diff --git a/lib/ui/exclude/exclude_single_page.dart b/lib/ui/exclude/exclude_single_page.dart index f47907b..ec84cd2 100644 --- a/lib/ui/exclude/exclude_single_page.dart +++ b/lib/ui/exclude/exclude_single_page.dart @@ -12,27 +12,57 @@ class ExcludeSinglePage extends StatefulWidget { } class _ExcludeSinglePageState extends State { + late TextEditingController _phoneController; + late TextEditingController _nameController; + + @override + void initState() { + super.initState(); + _phoneController = TextEditingController(); + _nameController = TextEditingController(); + } + + @override + void dispose() { + super.dispose(); + _phoneController.dispose(); + _nameController.dispose(); + } + @override Widget build(BuildContext context) { return ScaffoldThemeWidget( title: '添加单个或批量号码', bottom: "添加", onTap: () {}, + isOpacity: + _phoneController.text.isNotEmpty && _nameController.text.isNotEmpty, 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("名称", "请输入名称"), + addNumber("号码", "请输入号码", _phoneController), 15.heightBox, + addNumber("名称", "请输入名称", _nameController), + 30.heightBox, RichText( text: const TextSpan( children: [ - TextSpan(text: "使用说明:"), - TextSpan(text: "如输入000*,可屏蔽所有000开头的号码") + TextSpan( + text: "使用说明:\n", + style: TextStyle( + fontWeight: FontWeight.w600, + color: Colors.black38, + ), + ), + TextSpan( + text: "如输入000*,可屏蔽所有000开头的号码", + style: TextStyle( + color: Colors.black38, + ), + ), ], ), ), @@ -42,23 +72,52 @@ class _ExcludeSinglePageState extends State { ); } - addNumber(String title, content) { + addNumber(String title, content, TextEditingController controller) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, style: const TextStyle( - fontSize: 18, - color: Colors.black38, + fontSize: 16, + color: Color(0xFF999999), fontWeight: FontWeight.w600, ), ), 15.heightBox, TextField( + controller: controller, + onChanged: (value) { + setState(() {}); + }, decoration: InputDecoration( + contentPadding: EdgeInsets.all(30.w), hintText: content, - border: const OutlineInputBorder( + hintStyle: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Color(0xFF999999), + ), + fillColor: const Color(0xFFF9F9F9), + filled: true, + enabledBorder: const OutlineInputBorder( + /*边角*/ + borderRadius: BorderRadius.all( + Radius.circular(5), //边角为5 + ), + borderSide: BorderSide( + color: Colors.white, //边线颜色为白色 + width: 1, //边线宽度为2 + ), + ), + focusedBorder: const OutlineInputBorder( + borderSide: BorderSide( + color: Colors.white, //边框颜色为白色 + width: 1, //宽度为5 + ), + borderRadius: BorderRadius.all( + Radius.circular(5), //边角为30 + ), ), ), ), diff --git a/lib/ui/login/login_page.dart b/lib/ui/login/login_page.dart index 0029904..6341349 100644 --- a/lib/ui/login/login_page.dart +++ b/lib/ui/login/login_page.dart @@ -40,10 +40,12 @@ class _LoginPageState extends State { int _countDownNum = 59; late TextEditingController _phoneController; late TextEditingController _smsCodeController; - late FocusNode _phoneFocusNode ; + late FocusNode _phoneFocusNode; + late FocusNode _smsCodeFocusNode; bool _cantSelected = false; DateTime? _lastTap; + @override void initState() { super.initState(); @@ -121,35 +123,36 @@ class _LoginPageState extends State { blM: false, border: _phoneController.text.length != 11, opacity: _phoneController.text.length == 11 ? 1 : 0.4, - onTap: () async{ + onTap: () async { // DateTime? _lastTap; if (_phoneController.text.length < 11) { BotToast.showText(text: "请输入手机号"); - }else if(_smsCodeController.text.length < 6){ + } else if (_smsCodeController.text.length < 6) { BotToast.showText(text: "请输入验证码"); - }else if(!_chooseAgreement){ + } else if (!_chooseAgreement) { BotToast.showText(text: "请同意并勾选隐私政策"); - }else{ - if(_lastTap != null &&DateTime.now().difference(_lastTap!).inSeconds < 2){ + } else { + if (_lastTap != null && + DateTime.now().difference(_lastTap!).inSeconds < 2) { // BotToast.showText(text: "过快"); - return ; + return; } - _lastTap = DateTime.now(); - var base = await apiClient.request(API.app.login, - data: {'phone': _phoneController.text, 'code': _smsCodeController.text}); - if (base.code == 0) { - print("123123${base.data['token']}"); - await UserTool.userProvider.setToken(base.data['token']); + _lastTap = DateTime.now(); + var base = await apiClient.request(API.app.login, data: { + 'phone': _phoneController.text, + 'code': _smsCodeController.text + }); + if (base.code == 0) { + print("123123${base.data['token']}"); + await UserTool.userProvider.setToken(base.data['token']); // print(a); - // print("4567899"); - Get.offAll(const TabNavigator()); - } - else { - CloudToast.show(base.msg); - } + // print("4567899"); + Get.offAll(const TabNavigator()); + } else { + CloudToast.show(base.msg); } - }, - + } + }, text: "立即登录", ), 32.hb, @@ -223,10 +226,12 @@ class _LoginPageState extends State { await apiClient.request(API.app.captcha, data: { 'phone': _phoneController.text, }); - var res= RegExp( r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$'); - if((_phoneController.text).isNotEmpty && res.hasMatch(_phoneController.text)){ + var res = RegExp( + r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$'); + if ((_phoneController.text).isNotEmpty && + res.hasMatch(_phoneController.text)) { _beginCountDown(); - }else{ + } else { BotToast.showText(text: "手机号不能为空且手机号格式错误"); } if (_cantSelected) return; @@ -308,9 +313,10 @@ class _LoginPageState extends State { final TapGestureRecognizer recognizer = TapGestureRecognizer(); recognizer.onTap = () { if (kDebugMode) { - Get.to(()=>const ContentAuthorityPage()); + Get.to(() => const ContentAuthorityPage()); // print("点击协议了"); } + ///跳转到用户协议页面 }; return recognizer; @@ -336,27 +342,28 @@ class _LoginPageState extends State { : const Icon(CupertinoIcons.checkmark_circle, size: 18, color: Colors.blue), ), - RichText( - text: TextSpan( - text: "我已阅读并同意", - style: TextStyle( - color: BaseStyle.colorcccccc, fontSize: 12 * 2.sp), - children: [ - // TextSpan( - // text: '《用户服务协议》', - // style: TextStyle(color: kPrimaryColor, fontSize: 12 * 2.sp), - // recognizer: _recognizer(context, 2)), - // TextSpan( - // text: "和", - // style: TextStyle( - // color: BaseStyle.colorcccccc, fontSize: 12 * 2.sp), - // ), - TextSpan( - text: '《短信帮手隐私协议》', - style: TextStyle(color: kPrimaryColor, fontSize: 12 * 2.sp), - recognizer: _recognizer(context, 2)), - ])) + text: TextSpan( + text: "我已阅读并同意", + style: + TextStyle(color: BaseStyle.colorcccccc, fontSize: 12 * 2.sp), + children: [ + // TextSpan( + // text: '《用户服务协议》', + // style: TextStyle(color: kPrimaryColor, fontSize: 12 * 2.sp), + // recognizer: _recognizer(context, 2)), + // TextSpan( + // text: "和", + // style: TextStyle( + // color: BaseStyle.colorcccccc, fontSize: 12 * 2.sp), + // ), + TextSpan( + text: '《短信帮手隐私协议》', + style: TextStyle(color: kPrimaryColor, fontSize: 12 * 2.sp), + recognizer: _recognizer(context, 2)), + ], + ), + ), ], ), ); diff --git a/lib/ui/widget/scaffold_theme_widget.dart b/lib/ui/widget/scaffold_theme_widget.dart index a6a8e7d..0a03159 100644 --- a/lib/ui/widget/scaffold_theme_widget.dart +++ b/lib/ui/widget/scaffold_theme_widget.dart @@ -29,7 +29,7 @@ class ScaffoldThemeWidget extends StatefulWidget { required this.title, required this.child, required this.bottom, - this.isBorder = false, + this.isBorder = true, this.isOpacity = true, required this.onTap, }) : super(key: key); From 61e62e1e6252d021ebcf44e60c538bf32b10f04e Mon Sep 17 00:00:00 2001 From: datang Date: Tue, 13 Sep 2022 13:45:22 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=80=9A=E8=AE=AF?= =?UTF-8?q?=E5=BD=95=E6=9D=83=E9=99=90=E6=98=AF=E5=90=A6=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ui/exclude/exclude_contacts_page.dart | 22 ++- lib/ui/home/set/specify_phone_page.dart | 171 +++------------------- lib/ui/user/privacy_rights_page.dart | 37 ----- 3 files changed, 30 insertions(+), 200 deletions(-) diff --git a/lib/ui/exclude/exclude_contacts_page.dart b/lib/ui/exclude/exclude_contacts_page.dart index f72f850..2f9b778 100644 --- a/lib/ui/exclude/exclude_contacts_page.dart +++ b/lib/ui/exclude/exclude_contacts_page.dart @@ -1,11 +1,8 @@ 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 { @@ -16,20 +13,21 @@ class ExcludeContactsPage extends StatefulWidget { } class _ExcludeContactsPageState extends State { - late List contacts; + List? contacts; List numbers = []; List status = []; var flag = true; + bool _permissionDenied = false; @override void initState() { super.initState(); - _incrementCounter(); + _viewLoading(); } - Future _incrementCounter() async { + Future _viewLoading() async { contacts = await FlutterContacts.getContacts(); - for (var element in contacts) { + for (var element in contacts!) { final full = await FlutterContacts.getContact(element.id); numbers.add(full!.phones.first.number); status.add(false); @@ -40,17 +38,17 @@ class _ExcludeContactsPageState extends State { @override Widget build(BuildContext context) { var profileBuilder = FutureBuilder( - future: _incrementCounter(), + future: _viewLoading(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.waiting && flag) { flag = false; return Container(); } else { return ListView.builder( - itemCount: contacts.length, + itemCount: contacts!.length, itemBuilder: (context, i) => ListTile( title: Text( - contacts[i].displayName, + contacts![i].displayName, style: TextStyle( fontSize: 32.sp, fontWeight: FontWeight.w600, @@ -86,11 +84,11 @@ class _ExcludeContactsPageState extends State { title: "从通讯录添加", bottom: "添加", onTap: () { - if(status.contains(true)){ + if (status.contains(true)) { // BotToast.showText(text: "有"); Get.back(); - }else{ + } else { BotToast.showText(text: "还未选中手机号"); } }, diff --git a/lib/ui/home/set/specify_phone_page.dart b/lib/ui/home/set/specify_phone_page.dart index da382d9..33e9822 100644 --- a/lib/ui/home/set/specify_phone_page.dart +++ b/lib/ui/home/set/specify_phone_page.dart @@ -2,6 +2,7 @@ import 'package:call_log/call_log.dart'; import 'package:flustars/flustars.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:permission_handler/permission_handler.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'; @@ -13,6 +14,7 @@ import '../../../base/base_style.dart'; import '../../../model/phone_num_model.dart'; +import '../../widget/centertipsalterwidget.dart'; import '../../widget/scaffold_theme_widget.dart'; class SpecifyPhonePage extends StatefulWidget { @@ -63,8 +65,24 @@ class _SpecifyPhonePageState extends State { onTap: () {}, child: const CallRecordsList())); }), - _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () { - Get.to(() => (const ExcludeContactsPage())); + _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () async { + if(await Permission.contacts.isDenied){ + showDialog( + context: context, + builder: (context) { + return AlertDialog( + content: const Text('获取通讯录权限还未开启'), + actions: [ + ElevatedButton(onPressed: (){ + openAppSettings(); + }, + child: const Text("前往开启"),), + ], + ); + }); + }else{ + Get.to(() => (const ExcludeContactsPage())); + } }), _getAddPhone("添加单个或批量号码", "通过输入号码段添加批量号码", () { Get.to(() => (const ExcludeSinglePage())); @@ -105,155 +123,6 @@ class _SpecifyPhonePageState extends State { ], )), ); - // PloneBottom( - // 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( - // bottom: '添加', - // title: '从通话记录添加', - // isBorder: true, - // isOpacity: false, - // onTap: () { }, - // child: CallRecordsList() - // )); - // }), - // _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () { - // Get.to(() => (const ExcludeContactsPage())); - // }), - // _getAddPhone( - // "添加单个或批量号码", "通过输入号码段添加批量号码", () {}), - // ], - // )), - // PloneBottom( - // onTap: () { - // Navigator.pop(context); - // }, - // hPadding: 32, - // border: true, - // textColor: const Color(0xFF1890FF), - // color2: const Color(0xFFF9F9F9), - // color1: const Color(0xFFF9F9F9), - // text: "取消", - // ), - // 32.hb - // ], - // ), - // ); - // }, - // context: context); - // }, - // border: true, - // color2: const Color(0xFF74BCFF), - // color1: const Color(0xFF1890FF), - // text: "添加", - // ), - // Scaffold( - // appBar: AppBar( - // elevation: 0, - // title: Text( - // '发送号码设置', - // style: TextStyle( - // fontSize: BaseStyle.fontSize34, - // color: BaseStyle.color333333, - // fontWeight: FontWeight.bold), - // ), - // titleSpacing: 162.w, - // leading: const CloudBackButton(isSpecial: true), - // backgroundColor: kForeGroundColor), - // backgroundColor: kForeGroundColor, - // body: EasyRefresh( - // firstRefresh: true, - // controller: _refreshController, - // header: MaterialHeader(), - // // footer: MaterialFooter(), - // onRefresh: () async { - // // await userProvider.updateUserInfo(); - // - // setState(() {}); - // }, - // child: ListView( - // children: [ - // _getNullList(), - // PloneBottom( - // 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(() => const ScaffoldThemeWidget( - // bottom: '添加', - // title: '从通话记录添加', - // isBorder: true, - // isOpacity: false, - // child: CallRecordsList() - // )); - // }), - // _getAddPhone("通迅录添加", "通过本机通讯录添加号码", () { - // Get.to(() => (const ExcludeContactsPage())); - // }), - // _getAddPhone( - // "添加单个或批量号码", "通过输入号码段添加批量号码", () {}), - // ], - // )), - // PloneBottom( - // onTap: () { - // Navigator.pop(context); - // }, - // hPadding: 32, - // border: true, - // textColor: const Color(0xFF1890FF), - // color2: const Color(0xFFF9F9F9), - // color1: const Color(0xFFF9F9F9), - // text: "取消", - // ), - // 32.hb - // ], - // ), - // ); - // }, - // context: context); - // }, - // border: true, - // color2: const Color(0xFF74BCFF), - // color1: const Color(0xFF1890FF), - // text: "添加", - // ), - // ], - // )), - // ); } _getAddPhone(String title, String text, VoidCallback widget) { diff --git a/lib/ui/user/privacy_rights_page.dart b/lib/ui/user/privacy_rights_page.dart index 3bdec92..6cfd142 100644 --- a/lib/ui/user/privacy_rights_page.dart +++ b/lib/ui/user/privacy_rights_page.dart @@ -74,12 +74,7 @@ class _PrivacyRightsPageState extends State { bottomNavigationBar: GestureDetector( onTap: () async { await _launchUrl(); - // await launchUrlString("tel:13111111111"); }, - - // onTap: () async{ - // - // }, child: Container( margin: EdgeInsets.symmetric(horizontal: 64.w, vertical: 24.w), padding: EdgeInsets.symmetric(horizontal: 214.w, vertical: 26.w), @@ -95,21 +90,6 @@ class _PrivacyRightsPageState extends State { ); } - // Color getPermissionColor() { - // if(true){ - // return Colors.red; - // }else{ - // return Colors.green; - // } - // } - - // String getPermissionStu() { - // if (false) { - // return "未允许"; - // } else { - // return "已允许"; - // } - // } Future _launchUrl() async { if (!await launchUrl(_url)) { throw 'Could not launch $_url'; @@ -123,23 +103,6 @@ class _PrivacyRightsPageState extends State { openAppSettings(); setState(() {}); } - // if(!(sms && plone)){ - // // print(sms); - // // print(plone); - // openAppSettings(); - // }else{ - // // print("123123123123"); - // } - // await Permission.phone.request(); - // await Permission.sms.request(); - // Map statuses = await [ - // Permission.sms, - // Permission.phone, - // ].request(); - // - // openAppSettings(); - // print(await Permission.phone.request().isGranted); - // print(await Permission.sms.request().isGranted); }, title: Text( name,