diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index fd9dcbe..0aa2969 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -1,5 +1,3 @@ - - import 'dart:async'; @@ -7,9 +5,9 @@ import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:project_telephony/ui/home/content_connect_page.dart'; import 'package:project_telephony/ui/home/content_refuse_page.dart'; +import 'package:project_telephony/ui/user/privacy_rights_page.dart'; import 'package:project_telephony/utils/headers.dart'; - class HomePage extends StatefulWidget { const HomePage({Key? key}) : super(key: key); @@ -17,12 +15,11 @@ class HomePage extends StatefulWidget { _HomePageState createState() => _HomePageState(); } -bool sms=false; -bool plone=false; +bool sms = false; +bool plone = false; @override - -class _HomePageState extends State with WidgetsBindingObserver{ +class _HomePageState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); @@ -31,23 +28,27 @@ class _HomePageState extends State with WidgetsBindingObserver{ _listenForPermissionStatus(); setState(() {}); } + @override - void dispose(){ + void dispose() { super.dispose(); //页面销毁时移出监听者 WidgetsBinding.instance.removeObserver(this); } + Future _listenForPermissionStatus() async { - sms=await Permission.sms.request().isGranted; - plone =await Permission.phone.request().isGranted; + sms = await Permission.sms.request().isGranted; + plone = await Permission.phone.request().isGranted; + callLog = await Permission.callLog.request().isGranted; setState(() {}); } + @override - void didChangeAppLifecycleState(AppLifecycleState state){ + void didChangeAppLifecycleState(AppLifecycleState state) { super.didChangeAppLifecycleState(state); - switch (state){ - //应用状态处于闲置状态,并且没有用户的输入事件, - // 注意:这个状态切换到 前后台 会触发,所以流程应该是先冻结窗口,然后停止UI + switch (state) { + //应用状态处于闲置状态,并且没有用户的输入事件, + // 注意:这个状态切换到 前后台 会触发,所以流程应该是先冻结窗口,然后停止UI case AppLifecycleState.inactive: print("应用处于闲置状态,这种状态的应用应该假设他们可能在任何时候暂停 切换到后台会触发======"); break; @@ -63,6 +64,7 @@ class _HomePageState extends State with WidgetsBindingObserver{ break; } } + @override Widget build(BuildContext context) { return Scaffold( @@ -76,20 +78,25 @@ class _HomePageState extends State with WidgetsBindingObserver{ Positioned( top: 10.w, child: - // Container( - // height: 722.w, - // width: 722.w, - // decoration: BoxDecoration(image: DecorationImage(image:AssetImage(Assets.images.homeBg.path),fit:BoxFit.fill)), - // child: _warning(),) - Image.asset( + // Container( + // height: 722.w, + // width: 722.w, + // decoration: BoxDecoration(image: DecorationImage(image:AssetImage(Assets.images.homeBg.path),fit:BoxFit.fill)), + // child: _warning(),) + Image.asset( Assets.images.homeBg.path, height: 722.w, width: 722.w, ), ), - Positioned(top: 48.w,child: _warning()), + Positioned(top: 48.w, child: _warning()), Positioned(bottom: 64.w, child: _getBody()), - Align(child: SizedBox(width: double.infinity,height: 1600.w,),) + Align( + child: SizedBox( + width: double.infinity, + height: 1600.w, + ), + ) ], ), )); @@ -102,33 +109,50 @@ class _HomePageState extends State with WidgetsBindingObserver{ // return false; // } // } -_warning() { - return Offstage(offstage: (sms && plone) ,child: - GestureDetector( - onTap: (){ - // print(); - openAppSettings(); - }, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 64.w), - padding: EdgeInsets.symmetric(horizontal: 32.w,vertical: 20.w), - height: 88.w, - decoration: BoxDecoration( - borderRadius:BorderRadius.circular(8.w), - color: const Color(0xFFFFF2F2), - border: Border.all(width: 1.w,color: const Color(0xFFFFC8C8)) + _warning() { + return Offstage( + offstage: (sms && plone && callLog), + child: GestureDetector( + onTap: () { + // print(); + openAppSettings(); + }, + child: Container( + margin: EdgeInsets.symmetric(horizontal: 64.w), + padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 20.w), + height: 88.w, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8.w), + color: const Color(0xFFFFF2F2), + border: Border.all(width: 1.w, color: const Color(0xFFFFC8C8))), + child: Row( + children: [ + Image( + image: AssetImage(Assets.icons.horn.path), + width: 48.w, + height: 48.w, + ), + 16.wb, + Text( + "必须权限没有授予,本APP无法正常使用", + style: + TextStyle(color: const Color(0xFFFF3F3F), fontSize: 24.sp), + ), + 32.wb, + Image( + image: AssetImage(Assets.icons.right.path), + width: 28.w, + height: 28.w, + fit: BoxFit.fill, + ) + ], + ), + ), ), - child: Row(children: [ - Image(image: AssetImage(Assets.icons.horn.path),width: 48.w,height: 48.w - ,), - 16.wb, - Text("必须权限没有授予,本APP无法正常使用",style: TextStyle(color: const Color(0xFFFF3F3F),fontSize:24.sp ),) - ,32.wb, - Image(image: AssetImage(Assets.icons.right.path),width:28.w ,height: 28.w,fit:BoxFit.fill,) - ],), - ),),); -} -_getBody() { + ); + } + + _getBody() { return Container( padding: EdgeInsets.symmetric(horizontal: 64.w), child: Column( @@ -162,7 +186,6 @@ _getBody() { onTap: () { print(title); if (title == "接听后") { - Get.to(() => const ContentConnectPage()); } else { Get.to(() => const ContentRefusePage()); @@ -170,44 +193,47 @@ _getBody() { } }, child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(16.w), - gradient: LinearGradient( - begin: Alignment.centerLeft, - end: Alignment.centerRight, - colors: [cl1, cl2])), - width: 622.w, - height: 192.w, - child: Row(children: [ - Container( - padding: EdgeInsets.only(top: 40.w,left: 50.w - ), - child: - Column( - crossAxisAlignment: CrossAxisAlignment.start, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(16.w), + gradient: LinearGradient( + begin: Alignment.centerLeft, + end: Alignment.centerRight, + colors: [cl1, cl2])), + width: 622.w, + height: 192.w, + child: Row( children: [ - - Text(title, - style: TextStyle( - fontSize: 36.sp, - color: const Color(0xFFFFFFFF), - fontWeight: FontWeight.bold)), - 16.hb, - Text( - text, - style: TextStyle( - fontSize: 27.sp, - color: const Color(0xFFFFFFFF).withOpacity(0.6)), + Container( + padding: EdgeInsets.only(top: 40.w, left: 50.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title, + style: TextStyle( + fontSize: 36.sp, + color: const Color(0xFFFFFFFF), + fontWeight: FontWeight.bold)), + 16.hb, + Text( + text, + style: TextStyle( + fontSize: 27.sp, + color: const Color(0xFFFFFFFF).withOpacity(0.6)), + ), + ], + ), + ), + const Spacer(), + Padding( + padding: EdgeInsets.only(top: 40.w), + child: Image.asset( + image, + width: 166.w, + height: 152.w, + fit: BoxFit.fill, + ), ), ], - ),), - const Spacer(), - Padding(padding: EdgeInsets.only(top: 40.w),child: Image.asset( - image, - width: 166.w, - height: 152.w, - fit: BoxFit.fill, - ),) - ,],))); + ))); } } diff --git a/lib/ui/user/privacy_rights_page.dart b/lib/ui/user/privacy_rights_page.dart index ee466c9..511b154 100644 --- a/lib/ui/user/privacy_rights_page.dart +++ b/lib/ui/user/privacy_rights_page.dart @@ -6,7 +6,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; @@ -15,6 +14,7 @@ class PrivacyRightsPage extends StatefulWidget { @override _PrivacyRightsPageState createState() => _PrivacyRightsPageState(); } + final Uri _url = Uri.parse('https://www.dxbs.vip//explain.html'); // final Telephony telephony = Telephony.instance; // late final bool permissionsGranted; @@ -23,25 +23,27 @@ final Uri _url = Uri.parse('https://www.dxbs.vip//explain.html'); // void initState() async { // initPlatformState(); // } - bool sms=false; - bool plone=false; - +bool sms = false; +bool plone = false; +bool callLog = false; @override - class _PrivacyRightsPageState extends State { @override void initState() { super.initState(); - Future.delayed(const Duration(seconds: 0),() async{ + Future.delayed(const Duration(seconds: 0), () async { await _listenForPermissionStatus(); }); } + Future _listenForPermissionStatus() async { - sms=await Permission.sms.request().isGranted; - plone =await Permission.phone.request().isGranted; + sms = await Permission.sms.request().isGranted; + plone = await Permission.phone.request().isGranted; + callLog = await Permission.callLog.request().isGranted; setState(() {}); } + @override Widget build(BuildContext context) { return Scaffold( @@ -58,32 +60,37 @@ class _PrivacyRightsPageState extends State { leading: const CloudBackButton(isSpecial: true), backgroundColor: kForeGroundColor), backgroundColor: Colors.white, - body: Column(children: [ - _getRights("获取设备来电状态","用于获取来电状态",plone), - _getRights("获取设备短信权限","用于发送短信",sms), - _getRights("获取设备短信权限","用于发送短信",sms), - - ],) - - - , + body: Column( + children: [ + _getRights("获取设备来电状态", "用于获取来电状态", plone), + _getRights("获取设备短信权限", "用于发送短信", sms), + _getRights("获取设备通话记录", "用于获取来电", callLog), + ], + ), bottomNavigationBar: GestureDetector( - onTap:()async{ + 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) , - decoration: BoxDecoration(color:const Color(0xFFF9F9F9),borderRadius: BorderRadius.circular(8.w) ), - child: Text("查看使用说明",style: TextStyle(color: const Color(0xFF1890FF),fontSize: 28.sp),),),), + child: Container( + margin: EdgeInsets.symmetric(horizontal: 64.w, vertical: 24.w), + padding: EdgeInsets.symmetric(horizontal: 214.w, vertical: 26.w), + decoration: BoxDecoration( + color: const Color(0xFFF9F9F9), + borderRadius: BorderRadius.circular(8.w)), + child: Text( + "查看使用说明", + style: TextStyle(color: const Color(0xFF1890FF), fontSize: 28.sp), + ), + ), + ), ); } + // Color getPermissionColor() { // if(true){ // return Colors.red; @@ -104,10 +111,11 @@ class _PrivacyRightsPageState extends State { throw 'Could not launch $_url'; } } - _getRights( String name,String text,bool state){ - return ListTile( - onTap: ()async{ - if(!state){ + + _getRights(String name, String text, bool state) { + return ListTile( + onTap: () async { + if (!state) { openAppSettings(); } // if(!(sms && plone)){ @@ -132,19 +140,16 @@ class _PrivacyRightsPageState extends State { name, style: Theme.of(context).textTheme.titleMedium, ), - subtitle: Text( - text, + subtitle: Text( + text, ), trailing: Wrap( children: [ - Text(state ?"已允许":"未允许", - style: TextStyle(color: state ?Colors.green:Colors.red)), + Text(state ? "已允许" : "未允许", + style: TextStyle(color: state ? Colors.green : Colors.red)), const Icon(Icons.arrow_forward_ios), ], ), - ); -} - - + } } diff --git a/pubspec.lock b/pubspec.lock index 4776abf..dae8887 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -782,16 +782,20 @@ packages: permission_handler: dependency: "direct main" description: - name: permission_handler - url: "https://pub.dartlang.org" - source: hosted + path: "." + ref: HEAD + resolved-ref: bd29aebfbeba4072d78468d3f623017459cc9566 + url: "https://git.oa00.com/austin_dai/permission_handler.git" + source: git version: "10.0.0" permission_handler_android: dependency: transitive description: - name: permission_handler_android - url: "https://pub.dartlang.org" - source: hosted + path: "." + ref: HEAD + resolved-ref: b9cfe590e6f2ca13990c696802e285d747ac7067 + url: "https://git.oa00.com/austin_dai/permission_handler_android.git" + source: git version: "10.0.0" permission_handler_apple: dependency: transitive diff --git a/pubspec.yaml b/pubspec.yaml index d5dc671..267884f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,9 @@ dependencies: # 获取通话记录 call_log: ^4.0.0 - permission_handler: ^10.0.0 + permission_handler: + git: + url: https://git.oa00.com/austin_dai/permission_handler.git # 后台设置 flutter_background_service: ^2.1.3 flutter_background_service_android: ^2.0.3