From 5e40916e569b4ad470d7ff649896618e295b0c44 Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Thu, 6 Jun 2024 09:57:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=B8=BB=E5=8A=A8=E5=BC=95=E5=AF=BC?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=BC=80=E5=90=AF=E6=8E=A8=E9=80=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/lan/lan_en.json | 4 +- images/lan/lan_keys.json | 4 +- images/lan/lan_zh.json | 3 +- .../lockMian/lockMain/lockMain_logic.dart | 69 ++++++++++++------- lib/main/lockMian/lockMain/lockMain_page.dart | 3 - 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/images/lan/lan_en.json b/images/lan/lan_en.json index 447da036..101e886b 100755 --- a/images/lan/lan_en.json +++ b/images/lan/lan_en.json @@ -867,5 +867,7 @@ "自定义短信模版":"Custom SMS template", "自定义邮件模版":"Custom email template", "名称":"Name", - "星星锁": "Star lock" + "星星锁": "Star lock", + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "To receive important updates, please click 'OK' and enable notifications in the settings." + } diff --git a/images/lan/lan_keys.json b/images/lan/lan_keys.json index 1f83013b..c8130c70 100755 --- a/images/lan/lan_keys.json +++ b/images/lan/lan_keys.json @@ -899,5 +899,7 @@ "自定义短信模版":"自定义短信模版", "自定义邮件模版":"自定义邮件模版", "名称":"名称", - "星星锁": "星星锁" + "星星锁": "星星锁", + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" + } diff --git a/images/lan/lan_zh.json b/images/lan/lan_zh.json index 3c3bedf6..193c6d36 100755 --- a/images/lan/lan_zh.json +++ b/images/lan/lan_zh.json @@ -867,5 +867,6 @@ "自定义短信模版":"自定义短信模版", "自定义邮件模版":"自定义邮件模版", "名称":"名称", - "星星锁": "星星锁" + "星星锁": "星星锁", + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" } diff --git a/lib/main/lockMian/lockMain/lockMain_logic.dart b/lib/main/lockMian/lockMain/lockMain_logic.dart index 50c0c767..7b006eb1 100755 --- a/lib/main/lockMian/lockMain/lockMain_logic.dart +++ b/lib/main/lockMian/lockMain/lockMain_logic.dart @@ -1,7 +1,11 @@ import 'dart:async'; +import 'dart:io'; import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:get/get.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/main/lockMian/lockList/lockList_logic.dart'; +import 'package:star_lock/tools/showTipView.dart'; import '../../../app_settings/app_settings.dart'; import '../../../blue/blue_manage.dart'; @@ -17,7 +21,8 @@ class LockMainLogic extends BaseGetXController { Future getStarLockInfo( {bool isUnShowLoading = false}) async { - LockListInfoEntity entity = await ApiRepository.to.getStarLockListInfo( + final LockListInfoEntity entity = + await ApiRepository.to.getStarLockListInfo( pageNo: pageNo, pageSize: 50, isUnShowLoading: isUnShowLoading, @@ -59,33 +64,35 @@ class LockMainLogic extends BaseGetXController { /// 获取联网类型 void getConnectType() async { - var connectResult = await (Connectivity().checkConnectivity()); + final ConnectivityResult connectResult = + await (Connectivity().checkConnectivity()); if (connectResult == ConnectivityResult.mobile) { // _netType = "4G"; state.networkConnectionStatus.value = 1; - AppLog.log("网络连接: 4G 4G 4G 4G 4G"); + AppLog.log('网络连接: 4G 4G 4G 4G 4G'); } else if (connectResult == ConnectivityResult.wifi) { // _netType = "wifi"; state.networkConnectionStatus.value = 1; - AppLog.log("网络连接: wifi wifi wifi wifi wifi"); + AppLog.log('网络连接: wifi wifi wifi wifi wifi'); } else { // _netType = "未连接"; state.networkConnectionStatus.value = 0; - AppLog.log("网络连接: 未连接 未连接 未连接 未连接 未连接"); + AppLog.log('网络连接: 未连接 未连接 未连接 未连接 未连接'); // showToast("网络访问失败,请检查网络是否正常"); } } /// 判断网络是否连接 Future isConnected() async { - var connectResult = await (Connectivity().checkConnectivity()); + final ConnectivityResult connectResult = + await Connectivity().checkConnectivity(); return connectResult != ConnectivityResult.none; } /// 设置网络切换监听 - connectListener() async { + Future connectListener() async { Connectivity().onConnectivityChanged.listen((ConnectivityResult result) { - AppLog.log("设置网络切换监听:$result"); + AppLog.log('设置网络切换监听:$result'); if (state.networkConnectionStatus.value == 0 && result != ConnectivityResult.none) { // 从无网络到有网络 @@ -95,36 +102,52 @@ class LockMainLogic extends BaseGetXController { }); } + /// 检测推送是否开启 + Future checkWhetherPushIsEnabled() async { + bool notificationEnabled = false; + + if (Platform.isAndroid) { + notificationEnabled = await FlutterLocalNotificationsPlugin() + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.areNotificationsEnabled() ?? + false; + } else if (Platform.isIOS) { + notificationEnabled = await FlutterLocalNotificationsPlugin() + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: true, + badge: false, + sound: true, + ) ?? + false; + } + if (!notificationEnabled) { + //推送未开启 + ShowTipView().showIosTipWithContentDialog( + '为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。'.tr, () async { + openAppSettings(); + }); + } + } + @override void onReady() { - // TODO: implement onReady super.onReady(); - // 开启UDP UdpHelp().openUDP(); - BlueManage(); } @override void onInit() { - // TODO: implement onInit super.onInit(); - - // getLockInfo(); - // 设置网络变化监听 - // connectListener(); - // 获取网络连接状态 - // getConnectType(); + checkWhetherPushIsEnabled(); } @override void onClose() { - // TODO: implement onClose super.onClose(); - - // refreshController.dispose(); - // _teamEvent.cancel(); - // state.timer.cancel(); } } diff --git a/lib/main/lockMian/lockMain/lockMain_page.dart b/lib/main/lockMian/lockMain/lockMain_page.dart index 34319dbe..b23b80c4 100755 --- a/lib/main/lockMian/lockMain/lockMain_page.dart +++ b/lib/main/lockMian/lockMain/lockMain_page.dart @@ -54,9 +54,6 @@ class _StarLockMainPageState extends State with BaseWidget { WidgetsBinding.instance.addPostFrameCallback((_) async { setState(() {}); }); - // if (mounted) { - // setSŒe(() {}); - // } } @override