import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/main/lockDetail/lcokSet/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 Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: TitleAppBar( barTitle: '猫眼设置', haveBack: true, backgroundColor: AppColors.mainColor), body: Column( children: [ CommonItem( leftTitel: '猫眼工作模式', rightTitle: "", isHaveLine: true, isHaveDirection: true, action: () { Get.toNamed(Routers.catEyeWorkModePage); }), Obx(() => CommonItem( leftTitel: '自动亮屏', rightTitle: "", isHaveLine: true, isHaveDirection: false, isHaveRightWidget: true, rightWidget: _otherToDoSwitch(1))), Obx(() => CommonItem( leftTitel: '亮屏持续时间', rightTitle: state.selectBrightDuration.value, isHaveLine: true, isHaveDirection: true, action: () { _openBottomItemSheet(); })), Obx(() => CommonItem( leftTitel: '逗留警告', rightTitle: "", isHaveLine: true, isHaveRightWidget: true, rightWidget: _otherToDoSwitch(2), )), Obx(() => CommonItem( leftTitel: '异常警告', 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; break; case 2: //逗留警告 state.isStayWarning.value = value; break; case 3: //异常警告 state.isExceptionWarning.value = value; break; default: } }, ); } 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]; }, ); }); } }