import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/main/lockDetail/lockSet/catEyeSet/catEyeSet/catEyeSet_logic.dart'; import 'package:star_lock/tools/commonItem.dart'; import 'package:star_lock/tools/custom_bottom_sheet.dart'; import '../../../../../app_settings/app_colors.dart'; import '../../../../../tools/titleAppBar.dart'; class CatEyeSetPage extends StatefulWidget { const CatEyeSetPage({Key? key}) : super(key: key); @override State createState() => _CatEyeSetPageState(); } class _CatEyeSetPageState extends State { final logic = Get.put(CatEyeSetLogic()); final state = Get.find().state; @override void initState() { super.initState(); logic.getLockSettingInfoData(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: '猫眼设置'.tr, haveBack: true, backgroundColor: AppColors.mainColor), body: Column( children: [ Obx(() => CommonItem( leftTitel: '猫眼工作模式'.tr, rightTitle: state.selectCatEyeWorkMode.value, allHeight: 70.h, isHaveLine: true, isHaveDirection: true, action: () { Navigator.pushNamed(context, Routers.catEyeWorkModePage, arguments: { 'lockSetInfoData': state.lockSetInfoData.value, 'catEyeConfigData': state.lockSetInfoData.value .lockSettingInfo!.catEyeConfig!.isNotEmpty ? state.lockSetInfoData.value.lockSettingInfo! .catEyeConfig![0] : null }).then((value) { logic.getLockSettingInfoData(); }); })), Obx(() => CommonItem( leftTitel: '自动亮屏'.tr, rightTitle: "", isHaveLine: true, isHaveDirection: false, isHaveRightWidget: true, rightWidget: _otherToDoSwitch(1))), Obx(() => CommonItem( leftTitel: '亮屏持续时间'.tr, rightTitle: state.selectBrightDuration.value, isHaveLine: true, isHaveDirection: true, action: () { _openBottomItemSheet(); })), Obx(() => CommonItem( leftTitel: '逗留警告'.tr, rightTitle: "", isHaveLine: true, isHaveRightWidget: true, rightWidget: _otherToDoSwitch(2), )), Obx(() => CommonItem( leftTitel: '异常警告'.tr, rightTitle: "", isHaveLine: true, isHaveRightWidget: true, rightWidget: _otherToDoSwitch(3))), ], )); } CupertinoSwitch _otherToDoSwitch(int clickIndex) { bool isCheck = false; switch (clickIndex) { case 1: //自动亮屏 isCheck = state.isAutoBright.value; break; case 2: //逗留警告 isCheck = state.isStayWarning.value; break; case 3: //异常警告 isCheck = state.isExceptionWarning.value; break; default: } return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: isCheck, onChanged: (value) { switch (clickIndex) { case 1: //自动亮屏 { state.isAutoBright.value = value; logic.updateAutoLightScreenConfig(); } break; case 2: //逗留警告 { state.isStayWarning.value = value; logic.updateStayWarnConfig(); } break; case 3: //异常警告 { state.isExceptionWarning.value = value; logic.updateAbnormalWarnConfig(); } break; default: break; } }, ); } Future _openBottomItemSheet() async { showModalBottomSheet( context: context, shape: RoundedRectangleBorder( borderRadius: BorderRadiusDirectional.circular(10)), builder: (BuildContext context) { return AlertBottomWidget( topTitle: '', items: state.brightDurationTimeList, chooseCallback: (value) { state.selectBrightDuration.value = state.brightDurationTimeList[value]; logic.updateLightScreenTimeConfig(); }, ); }); } }