You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

355 lines
11 KiB

2 years ago
import 'dart:async';
2 years ago
import 'package:bot_toast/bot_toast.dart';
2 years ago
import 'package:flutter/material.dart';
2 years ago
import 'package:flutter_background_service/flutter_background_service.dart';
2 years ago
import 'package:flutter_xupdate/flutter_xupdate.dart';
2 years ago
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';
2 years ago
import 'package:project_telephony/ui/home/set/phone_set_page.dart';
2 years ago
import 'package:project_telephony/ui/user/privacy_rights_page.dart';
2 years ago
import 'package:project_telephony/utils/headers.dart';
2 years ago
import '../../utils/toast/cloud_toast.dart';
2 years ago
import '../user/privacy_rights_page.dart';
2 years ago
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
2 years ago
2 years ago
bool sms = false;
bool plone = false;
2 years ago
bool addressBook = false;
2 years ago
bool kg = false;
2 years ago
2 years ago
final service = FlutterBackgroundService();
2 years ago
2 years ago
@override
2 years ago
class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
2 years ago
@override
void initState() {
super.initState();
2 years ago
initXUpdate();
//页面初始化的时候,添加一个状态的监听者
WidgetsBinding.instance.addObserver(this);
2 years ago
_listenForPermissionStatus();
setState(() {});
}
2 years ago
@override
2 years ago
void dispose() {
super.dispose();
//页面销毁时移出监听者
WidgetsBinding.instance.removeObserver(this);
2 years ago
}
2 years ago
2 years ago
Future<void> _listenForPermissionStatus() async {
2 years ago
sms = await Permission.sms.request().isGranted;
plone = await Permission.phone.request().isGranted;
callLog = await Permission.callLog.request().isGranted;
2 years ago
addressBook = await Permission.contacts.request().isGranted;
2 years ago
kg = await service.isRunning();
2 years ago
setState(() {});
}
2 years ago
2 years ago
///初始化
void initXUpdate() {
FlutterXUpdate.init(
///是否输出日志
debug: true,
///是否使用post请求
isPost: false,
///post请求是否是上传json
isPostJson: false,
///请求响应超时时间
timeout: 25000,
///是否开启自动模式
isWifiOnly: false,
///是否开启自动模式
isAutoMode: false,
///需要设置的公共参数
supportSilentInstall: false,
///在下载过程中,如果点击了取消的话,是否弹出切换下载方式的重试提示弹窗
enableRetry: false)
.then((value) {
// CloudToast.show("初始化成功: $value");
}).catchError((error) {
print(error);
});
// FlutterXUpdate.setErrorHandler(
// onUpdateError: (Map<String, dynamic> message) async {
// print(message);
// setState(() {
// _message = "$message";
// });
// });
}
2 years ago
@override
Widget build(BuildContext context) {
return Scaffold(
2 years ago
backgroundColor: Colors.white,
extendBodyBehindAppBar: true,
extendBody: true,
body: SafeArea(
child: Stack(
2 years ago
// fit: StackFit.expand,
2 years ago
children: [
Positioned(
top: 10.w,
2 years ago
child:
2 years ago
// 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,
),
),
2 years ago
Positioned(top: 48.w, child: _warning()),
2 years ago
// Positioned(child: PloneBottom(onTap: (){
// showDialog(context: context, builder: (context){
// return const AppDialog();
// });
//
// })),
2 years ago
Positioned(bottom: 64.w, child: _getBody()),
2 years ago
Align(
child: SizedBox(
width: double.infinity,
height: 1600.w,
),
)
2 years ago
],
),
));
2 years ago
}
// bool _getPermissions() {
// if(sms && plone){
// return true;
// }else{
// return false;
// }
// }
2 years ago
// String _text(){
// if(!(sms && plone && callLog && kg)){
// if(!(sms && plone && callLog )){
// return "";
// // return "必须权限没有授予本APP无法正常使用";
// }if(!kg){
// return "功能开关未开启";
// }
// }else{
// return "";
// }
// }
2 years ago
_warning() {
return Offstage(
offstage: (sms && plone && callLog && addressBook && kg),
2 years ago
child: GestureDetector(
onTap: () {
if (!(sms && plone && callLog && addressBook && kg)) {
if (!(sms && plone && callLog && addressBook)) {
2 years ago
Get.to(() => const PrivacyRightsPage(name: "权限说明"));
2 years ago
// Get.to(()=>const TabNavigator(index: 1,));
2 years ago
} else {
2 years ago
BotToast.showText(text: '功能开关未开启');
2 years ago
}
}
2 years ago
// openAppSettings();
2 years ago
},
2 years ago
child: Container(
2 years ago
width: 622.w,
margin: EdgeInsets.symmetric(horizontal: 64.w),
2 years ago
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(
!(sms && plone && callLog && addressBook)
2 years ago
? "必须权限没有授予本APP无法正常使用"
: "功能开关未开启,请到我的页面开启",
2 years ago
style:
TextStyle(color: const Color(0xFFFF3F3F), fontSize: 24.sp),
),
!(sms && plone && callLog && addressBook) ? 32.wb : 0.wb,
!(sms && plone && callLog && addressBook)
2 years ago
? Image(
image: AssetImage(Assets.icons.right.path),
width: 28.w,
height: 28.w,
fit: BoxFit.fill,
)
: const SizedBox()
2 years ago
],
),
),
2 years ago
),
2 years ago
);
}
_getBody() {
2 years ago
return Container(
2 years ago
padding: EdgeInsets.symmetric(horizontal: 64.w),
2 years ago
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2 years ago
"短信帮手",
2 years ago
style: TextStyle(
fontSize: 64.sp,
2 years ago
color: const Color(0xFF333333),
2 years ago
fontWeight: FontWeight.bold),
),
2 years ago
24.hb,
2 years ago
Text(
"希望能成为您的短信小助手",
style: TextStyle(fontSize: 32.sp, color: const Color(0xFF999999)),
),
2 years ago
48.hb,
_getSet(),
32.hb,
2 years ago
_getContainer("接听后", "编辑接听后发送的短信内容", Assets.images.answer.path,
const Color(0xFF74BCFF), const Color(0xFF1890FF)),
30.hb,
_getContainer("拒接/未接后", "编辑拒接/未接后发送的短信内容", Assets.images.refused.path,
const Color(0xFF72E4C8), const Color(0xFF13CA9D))
],
),
);
}
2 years ago
_getSet() {
return GestureDetector(
2 years ago
onTap: () {
Navigator.of(context)
.push(
MaterialPageRoute(builder: (_) => const PhoneSetPage()),
)
.then((val) => _listenForPermissionStatus());
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 42.w, vertical: 20.w),
decoration: BoxDecoration(
color: const Color(0xFFF2F9FF),
border: Border.all(color: const Color(0xFF1890FF), width: 2.w),
borderRadius: BorderRadius.circular(16.w)),
child: Row(
children: [
SizedBox(
width: 48.w,
height: 48.w,
child: Image.asset(Assets.icons.set.path),
2 years ago
),
2 years ago
16.wb,
Text(
"短信发送号码设置",
style:
TextStyle(fontSize: 28.sp, color: const Color(0xFF1890FF)),
),
190.wb,
SizedBox(
width: 48.w,
height: 48.w,
child: const Icon(
Icons.chevron_right,
color: Color(0xFF1890FF),
),
),
],
),
));
2 years ago
}
2 years ago
// void checkUpdateDefault() {
// FlutterXUpdate.checkUpdate(url: 'https://gitee.com/xuexiangjys/XUpdate/raw/master/jsonapi/update_test.json');
// }
2 years ago
_getContainer(String title, String text, String image, Color cl1, Color cl2) {
return GestureDetector(
2 years ago
onTap: () async {
FlutterXUpdate.checkUpdate(
url:'');
2 years ago
// PackageInfo packageInfo = await PackageInfo.fromPlatform();
// String version = packageInfo.version;//版本号
// String buildNumber = packageInfo.buildNumber;//版本构建号
// print(version);
// print(buildNumber);
// print(title);
2 years ago
// if (title == "接听后") {
// Get.to(() => const ContentConnectPage());
// } else {
// Get.to(() => const ContentRefusePage());
// // print("未接听");
// }
2 years ago
},
2 years ago
child: Container(
2 years ago
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(
2 years ago
children: [
2 years ago
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,
),
),
2 years ago
],
2 years ago
)));
2 years ago
}
}