import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/flavors.dart'; import 'package:star_lock/mine/mineSet/mineSet/mineSet_logic.dart'; import 'package:star_lock/mine/mineSet/mineSet/mineSet_state.dart'; import 'package:star_lock/tools/wechat/customer_tool.dart'; import '../../../appRouters.dart'; import '../../../app_settings/app_colors.dart'; import '../../../tools/commonItem.dart'; import '../../../tools/showTipView.dart'; import '../../../tools/submitBtn.dart'; import '../../../tools/titleAppBar.dart'; import '../../../tools/wechat/wechatManageTool.dart'; import '../../../tools/wechat/wx_push_miniProgram/wx_push_miniProgram.dart'; import '../../../translations/app_dept.dart'; import '../../../translations/current_locale_tool.dart'; class MineSetPage extends StatefulWidget { MineSetPage({Key? key, this.showAppBar = true, this.showAbout = false}) : super(key: key); bool showAppBar; bool showAbout; @override State createState() => _MineSetPageState(); } class _MineSetPageState extends State with WidgetsBindingObserver, AutomaticKeepAliveClientMixin { final MineSetLogic logic = Get.put(MineSetLogic()); final MineSetState state = Get.find().state; @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); logic.userSettingsInfoRequest(); } @override void didChangeAppLifecycleState(AppLifecycleState state) { super.didChangeAppLifecycleState(state); if (state == AppLifecycleState.resumed) { // 应用从后台返回前台 // 在这里执行相应的操作 _checkNotificationPermission(); } } @override Widget build(BuildContext context) { _checkNotificationPermission(); return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: widget.showAppBar ? F.sw( skyCall: () => TitleAppBar( barTitle: '更多设置'.tr, haveBack: true, backgroundColor: AppColors.mainColor, ), xhjCall: () => TitleAppBar( barTitle: '更多设置'.tr, haveBack: true, backgroundColor: Colors.white, iconColor: AppColors.blackColor, titleColor: AppColors.blackColor, )) : null, body: SingleChildScrollView( child: styleHierarchy(), ), floatingActionButton: widget.showAppBar ? null : GestureDetector( onTap: () { WechatManageTool.getAppInfo(() { WxPushWeChatMiniProgramTool.pushWeChatMiniProgram( F.wechatAppInfo.wechatAppId, F.wechatAppInfo.universalLink); }); }, child: ClipRRect( borderRadius: BorderRadius.circular(40.r), child: Image.asset( 'images/mine/icon_mine_wan_wanshifu.png', width: 80.w, height: 80.w, ), ), )); } //样式层级 Widget styleHierarchy() { Widget view = getListDataView(); view = F.sw( skyCall: () => view, xhjCall: () => Column( children: [ Container( width: 1.sw, height: 0.2.sw, margin: EdgeInsets.only( top: 15.h, left: 20.w, right: 20.w, bottom: 20.h), padding: EdgeInsets.symmetric(horizontal: 25.w), decoration: BoxDecoration( image: const DecorationImage( image: AssetImage('images/xhj_main_bg.jpg'), fit: BoxFit.cover, ), borderRadius: BorderRadius.circular(20.r), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.15), offset: const Offset(0, 0), blurRadius: 10.r, spreadRadius: 0, ), ], ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( '系统设置'.tr, style: TextStyle( color: AppColors.blackColor, fontSize: 28.sp, fontWeight: FontWeight.w600, ), ), Text( '系统的全局配置在此项内进行设置'.tr, style: TextStyle( color: AppColors.blackColor.withOpacity(0.6), fontSize: 20.sp, fontWeight: FontWeight.w600, ), ), ], ), ), Container( margin: EdgeInsets.only( top: 20.h, left: 20.w, right: 20.w, bottom: 40.h), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(20.r))), child: ClipRRect( borderRadius: BorderRadius.circular(20.r), child: view, ), ), F.sw(skyCall: () => const SizedBox(), xhjCall: keyBottomWidget), ], )); return view; } Widget getListDataView() { // 检测系统语言是否为中文 return Column( children: [ /* 2024-01-12 会议确定去掉“提示音、触摸开锁” by DaisyWu CommonItem( leftTitel: TranslationLoader.lanKeys!.prompTone!.tr, rightTitle: "", isHaveLine: true, isHaveRightWidget: true, rightWidget: SizedBox( width: 60.w, height: 50.h, child: Obx(() => _isPrompToneSwitch()))), CommonItem( leftTitel: TranslationLoader.lanKeys!.touchUnlock!.tr, rightTitle: "", isHaveLine: true, isHaveRightWidget: true, rightWidget: SizedBox( width: 60.w, height: 50.h, child: Obx(() => _isTouchUnlockSwitch()))), */ F.sw( skyCall: () => const SizedBox(), xhjCall: () => CommonItem( leftTitel: '个人信息'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.minePersonInfoPage); })), CommonItem( leftTitel: '消息推送'.tr, rightTitle: '', isHaveRightWidget: true, isHaveLine: F.sw( skyCall: () => F.appFlavor == Flavor.sky, xhjCall: () => true), rightWidget: SizedBox( width: 60.w, height: 50.h, child: Obx(_isPushNotificationSwitch))), // if (F.appFlavor == Flavor.sky) Visibility( visible: state.currentLanguageCode == 'zh_CN', child: CommonItem( leftTitel: '微信公众号推送'.tr, rightTitle: '', isHaveLine: true, isHaveRightWidget: true, rightWidget: SizedBox( width: 60.w, height: 50.h, child: Obx(_isWechatPublicAccountPushSwitch), ), ), ), SizedBox(height: 10.h), CommonItem( leftTitel: '锁用户管理'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.lockUserManageLisPage); }), CommonItem( leftTitel: '授权管理员'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.authorizedAdministratorListPage); }), //by DaisyWu 新增--批量授权 if (!F.isProductionEnv) CommonItem( leftTitel: '批量授权'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.authorityManagementPage); // Toast.show(msg: "功能暂未开放"); }), CommonItem( leftTitel: '网关'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.gatewayListPage); }), CommonItem( leftTitel: '锁分组'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.lockGroupListPage); }), CommonItem( leftTitel: '转移智能锁'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.transferSmartLockPage); }), //暂无网关屏蔽 // CommonItem( // leftTitel: '转移网关'.tr, // rightTitle: '', // isHaveLine: true, // isHaveDirection: true, // action: () { // Get.toNamed(Routers.selectGetewayListPage); // }), SizedBox( height: 10.h, ), // AppLog.log('state.currentLanguageName: ${state.currentLanguageName} state.currentLanguage.value: ${state.currentLanguage.value}'); CommonItem( leftTitel: '多语言'.tr, rightTitle: state.currentLanguageName, isHaveLine: true, isHaveDirection: true, action: () async { // Get.toNamed(Routers.mineMultiLanguagePage); await Get.toNamed(Routers.mineMultiLanguagePage)!.then((value) { setState(() { if (value.containsKey('currentLanguage')) { state.currentLanguage.value = value['currentLanguage']; } }); }); }), /* 2024-01-12 会议确定去掉“锁屏” by DaisyWu Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.lockScreen!.tr, rightTitle: (state.lockScreen.value == 1 ? TranslationLoader.lanKeys!.opened!.tr : TranslationLoader.lanKeys!.closed!.tr), isHaveLine: true, isHaveDirection: true, action: () { Navigator.pushNamed(context, Routers.lockScreenPage, arguments: {'isOn': state.lockScreen.value}).then((value) { logic.userSettingsInfoRequest(); }); })), */ Obx(() => CommonItem( leftTitel: '隐藏无效开锁权限'.tr, rightTitle: (state.hideExpiredAccessFlag.value == 1 ? '已开启'.tr : '已关闭'.tr), isHaveLine: true, isHaveDirection: true, action: () { Navigator.pushNamed( context, Routers.hideInvalidUnlockPermissionsPage, arguments: { 'isOn': state.hideExpiredAccessFlag.value }).then((Object? value) { logic.userSettingsInfoRequest(); }); })), otherItem( leftTitle: 'APP开锁时需手机连网的锁'.tr, isHaveLine: true, action: () { Navigator.pushNamed( context, Routers.aPPUnlockNeedMobileNetworkingLockPage); }), if (!F.isSKY) CommonItem( leftTitel: '增值服务'.tr, isHaveLine: true, isHaveDirection: true, action: () { Get.back(); Get.toNamed(Routers.valueAddedServicesPage); }, ), SizedBox( height: 10.h, ), CommonItem( leftTitel: 'Amazon Alexa'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.amazonAlexaPage, arguments: { 'isAmazonAlexa': state.isAmazonAlexa.value, 'amazonAlexaData': state.amazonAlexaData.value }); }), CommonItem( leftTitel: 'Google Home'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.googleHomePage, arguments: { 'isGoogleHome': state.isGoogleHome.value, 'googleHomeData': state.googleHomeData.value })?.then((Object? value) { logic.userSettingsInfoRequest(); }); }), // if (!F.isProductionEnv) // CommonItem( // leftTitel: '小米IOT平台'.tr, // rightTitle: '', // isHaveLine: widget.showAbout, // isHaveDirection: true, // action: () { // logic.showToast('功能暂未开放'.tr); // }), if (!F.isSKY) CommonItem( leftTitel: '客服'.tr, isHaveLine: widget.showAbout, isHaveDirection: true, action: () { WechatManageTool.getAppInfo(CustomerTool.openCustomerService); }, ), if (widget.showAbout) CommonItem( leftTitel: '关于'.tr, isHaveLine: false, isHaveDirection: true, action: () { Get.back(); Get.toNamed(Routers.aboutPage); }, ), // CommonItem(leftTitel:TranslationLoader.lanKeys!.valueAddedServices!.tr, rightTitle:"", isHaveDirection: true, action: (){ // // }), SizedBox( height: F.sw(skyCall: () => 50.h, xhjCall: () => 0.0), ), // CommonItem(leftTitel:TranslationLoader.lanKeys!.about!.tr, rightTitle:"", isHaveLine: true, isHaveDirection: true, action: (){ // // }), // SizedBox(height: 10.h,), // CommonItem(leftTitel:TranslationLoader.lanKeys!.userAgreement!.tr, rightTitle:"", isHaveLine: true, isHaveDirection: true, action: (){ // // }), // CommonItem(leftTitel:TranslationLoader.lanKeys!.privacyPolicy!.tr, rightTitle:"", isHaveLine: true, isHaveDirection: true, action: (){ // // }), // CommonItem(leftTitel:TranslationLoader.lanKeys!.personalInformationCollectionList!.tr, rightTitle:"", isHaveLine: true, isHaveDirection: true, action: (){ // // }), // CommonItem(leftTitel:TranslationLoader.lanKeys!.applicationPermissionDescription!.tr, rightTitle:"", isHaveLine: true, isHaveDirection: true, action: (){ // // }), // CommonItem(leftTitel:TranslationLoader.lanKeys!.thirdPartyInformationSharingList!.tr, rightTitle:"", isHaveLine: true, isHaveDirection: true, action: (){ // // }), F.sw(skyCall: keyBottomWidget, xhjCall: () => const SizedBox()) ], ); } Widget keyBottomWidget() { return Padding( padding: F.sw( skyCall: () => EdgeInsets.zero, xhjCall: () => EdgeInsets.symmetric(horizontal: 15.w)), child: Column( children: [ SubmitBtn( btnName: '退出'.tr, isDelete: true, padding: EdgeInsets.symmetric(horizontal: 15.w), onClick: () { //退出登录 ShowTipView().showIosTipWithContentDialog( '确定要退出吗?'.tr, logic.userLogoutRequest); // showLoginOutAlertTipDialog(); }), Container( padding: EdgeInsets.only(left: 30.w, top: 30.h), // color: Colors.red, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ TextButton( child: Text( '删除账号'.tr, style: TextStyle( color: AppColors.darkGrayTextColor, fontSize: 18.sp), ), onPressed: () { ShowTipView().showIosTipWithContentDialog( '删除账号后,你的所有信息及相关记录都会从平台彻底删除,且不可恢复,是否删除?'.tr, () { //安全验证 Get.toNamed(Routers.safeVerifyPage); }); }, ), ], ), ), SizedBox( height: 30.h, ) ], ), ); } Widget otherItem( {String? leftTitle, bool? isHaveLine, Function()? action, double? allHeight}) { return GestureDetector( onTap: action, child: Container( width: 1.sw, padding: EdgeInsets.only(left: 20.w, top: 15.h, bottom: 15.h, right: 10.w), decoration: BoxDecoration( color: Colors.white, border: isHaveLine! ? Border( bottom: BorderSide( color: AppColors.greyLineColor, // 设置边框颜色 width: 2.0.h, // 设置边框宽度 ), ) : null, ), child: Row( children: [ Expanded( child: Text(leftTitle!, style: TextStyle(fontSize: 22.sp))), SizedBox(width: 10.w), if (CurrentLocaleTool.getCurrentLocaleString() == ExtensionLanguageType.fromLanguageType(LanguageType.hebrew) .toString() || CurrentLocaleTool.getCurrentLocaleString() == ExtensionLanguageType.fromLanguageType(LanguageType.arabic) .toString()) Image.asset( 'images/icon_left_grey.png', width: 21.w, height: 21.w, ) else Image.asset( 'images/icon_right_grey.png', width: 12.w, height: 21.w, ), SizedBox(width: 5.w), ], ), ), ); } //确认弹窗 // void _showDialog(widgetContext) { // showCupertinoDialog( // context: widgetContext, // builder: (context) { // return CupertinoAlertDialog( // title: Text(TranslationLoader.lanKeys!.deleteAccountTips!.tr), // actions: [ // CupertinoDialogAction( // child: Text(TranslationLoader.lanKeys!.cancel!.tr), // onPressed: () { // Navigator.of(context).pop(); // }, // ), // CupertinoDialogAction( // child: Text(TranslationLoader.lanKeys!.sure!.tr), // onPressed: () { // Get.back(); // //安全验证 // Get.toNamed(Routers.safeVerifyPage); // setState(() {}); // }, // ), // ], // ); // }, // ); // } // void showLoginOutAlertTipDialog() { // showCupertinoDialog( // context: context, // builder: (context) { // return CupertinoAlertDialog( // title: const Text("提示"), // content: const Text('确定要退出吗?'), // actions: [ // CupertinoDialogAction( // child: Text(TranslationLoader.lanKeys!.cancel!.tr), // onPressed: () { // Get.back(); // }, // ), // CupertinoDialogAction( // child: const Text("退出"), // onPressed: () { // Get.back(); // logic.userLogoutRequest(); // }, // ), // ], // ); // }, // ); // } // CupertinoSwitch _isPrompToneSwitch() { // return CupertinoSwitch( // activeColor: CupertinoColors.activeBlue, // trackColor: CupertinoColors.systemGrey5, // thumbColor: CupertinoColors.white, // value: state.isPrompTone.value, // onChanged: (bool value) { // state.isPrompTone.value = !state.isPrompTone.value; // logic.updatePrompToneRequest(); // }, // ); // } // CupertinoSwitch _isTouchUnlockSwitch() { // return CupertinoSwitch( // activeColor: CupertinoColors.activeBlue, // trackColor: CupertinoColors.systemGrey5, // thumbColor: CupertinoColors.white, // value: state.isTouchUnlock.value, // onChanged: (bool value) { // state.isTouchUnlock.value = !state.isTouchUnlock.value; // logic.updateTouchUnlockRequest(); // }, // ); // } //微信公众号推送开关 CupertinoSwitch _isWechatPublicAccountPushSwitch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.isWechatPublicAccountPush.value, onChanged: (bool value) { state.isWechatPublicAccountPush.value = !state.isWechatPublicAccountPush.value; logic.setMpWechatPushSwitchRequest(context); }, ); } CupertinoSwitch _isPushNotificationSwitch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.isPushNotification.value, onChanged: (bool value) { // state.isPushNotification.value = !state.isPushNotification.value; openAppSettings(); }, ); } Future _checkNotificationPermission() async { bool notificationEnabled = false; if (Platform.isAndroid) { notificationEnabled = await state.flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< AndroidFlutterLocalNotificationsPlugin>() ?.areNotificationsEnabled() ?? false; } else if (Platform.isIOS) { notificationEnabled = await state.flutterLocalNotificationsPlugin .resolvePlatformSpecificImplementation< IOSFlutterLocalNotificationsPlugin>() ?.requestPermissions( alert: true, badge: false, sound: true, ) ?? false; } if (notificationEnabled) { state.isPushNotification.value = true; } else { state.isPushNotification.value = false; } } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override bool get wantKeepAlive => true; }