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/app_settings/app_settings.dart'; import 'package:star_lock/main/lockDetail/lockSet/faceUnlock/faceUnlock_logic.dart'; import 'package:star_lock/main/lockDetail/lockSet/faceUnlock/faceUnlock_state.dart'; import 'package:star_lock/tools/custom_bottom_sheet.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/commonItem.dart'; import '../../../../tools/pickers/pickers.dart'; import '../../../../tools/titleAppBar.dart'; class FaceUnlockPage extends StatefulWidget { const FaceUnlockPage({Key? key}) : super(key: key); @override State createState() => _FaceUnlockPageState(); } class _FaceUnlockPageState extends State { final FaceUnlockLogic logic = Get.put(FaceUnlockLogic()); final FaceUnlockState state = Get.find().state; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: TitleAppBar( barTitle: '面容开锁设置'.tr, haveBack: true, backgroundColor: AppColors.mainColor), body: Obx(() => ListView( children: [ Container( margin: EdgeInsets.only(left: 20.w), child: CommonItem( leftTitel: '面容开锁'.tr, rightTitle: '', allHeight: 70.h, isHaveLine: true, isHaveRightWidget: true, rightWidget: SizedBox( width: 60.w, height: 50.h, child: _switch(1))), ), _buildSubTitleItem( '感应距离'.tr, // TranslationLoader.lanKeys!.sensingDistanceTip!.tr, logic.getSensingDistanceString(), state.senseDistance.value, state.faceOn.value, () { _openBottomItemSheet(state.senseDistanceList.value, 0); }), SizedBox(height: 30.h), _buildSubTitleItem( '防误开'.tr, state.antiMisoperation.value == 0 ? '防误开已关闭,关门后仍可使用面容开锁'.tr : '防误开已打开,开锁后'.tr + state.antiMisoperation.value.toString() + '秒内不可使用面容开锁'.tr, // state.antiMisoperation.value == 0 ? '关闭' : '${state.antiMisoperation.value}' + '秒'.tr, state.faceOn.value, () { Pickers.showSinglePicker(Get.context!, data: state.antiMisoperationStrList.value, onConfirm: (var data, int position) { AppLog.log('data = $data, position = $position'); state.antiMisoperation.value = position; state.setType.value = 2; logic.sendFaceUnlock(); }); // _openBottomItemSheet(state.antiMisoperationStrList.value, 1); }), Expanded(child: SizedBox(height: 30.h)), _buildTipsView(), SizedBox( height: 60.h, ) ], ))); } Widget _buildSubTitleItem(String leftStr, String subTitle, String rightStr, bool isAble, Function()? action) { return GestureDetector( onTap: isAble ? action : null, child: Container( margin: EdgeInsets.only(left: 20.sp, right: 20.sp, top: 20.h), color: Colors.white, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ SizedBox( width: 20.w, ), Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ Container( alignment: Alignment.centerLeft, child: Text( leftStr, style: TextStyle( fontSize: 24.sp, color: isAble ? Colors.black : AppColors.placeholderTextColor), ), ), SizedBox( height: 10.h, ), Container( alignment: Alignment.centerLeft, child: Text( subTitle, style: TextStyle( fontSize: 20.sp, color: AppColors.btnDisableColor), ), ) ], )), SizedBox( width: 20.w, ), Text( rightStr, style: TextStyle( fontSize: 22.sp, color: isAble ? Colors.black : AppColors.placeholderTextColor), ), SizedBox( width: 10.w, ), Image.asset( 'images/icon_right_grey.png', width: 12.w, height: 21.w, ) ], ), ), ); } Widget _buildTipsView() { return Container( width: ScreenUtil().screenWidth - 40.w, margin: EdgeInsets.only(left: 20.w, right: 20.w, bottom: 10.h), decoration: BoxDecoration( color: AppColors.mainBackgroundColor, borderRadius: BorderRadius.circular(10.0), ), child: Padding( padding: EdgeInsets.only(left: 20.w, top: 30.h, bottom: 40.h, right: 15.w), child: RichText(text: state.tipsPreviewSpan)), ); } CupertinoSwitch _switch(int getIndex) { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.faceOn.value, // getIndex == 1 ? state.faceOn.value : state.autoBright.value, onChanged: (bool value) { if (getIndex == 1) { //设置面容开锁开关 state.faceOn.value = value; state.setType.value = 0; logic.sendFaceUnlock(); } }, ); } Future _openBottomItemSheet(List bottomItemList, int clickIndex) async { showModalBottomSheet( context: context, shape: RoundedRectangleBorder( borderRadius: BorderRadiusDirectional.circular(10)), builder: (BuildContext context) { return AlertBottomWidget( topTitle: '', items: bottomItemList, chooseCallback: (int value) { state.senseDistance.value = state.senseDistanceList.value[value]; state.setType.value = 1; logic.sendFaceUnlock(); }, ); }); } }