Daisy 28554dd0e4 1,新增设置面容开锁接口对接
2,新增设置面容感应距离接口对接
3,新增设置面容防误开接口对接
4,新增设置面容自动亮屏接口对接
2024-04-08 11:01:24 +08:00

213 lines
7.0 KiB
Dart

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/main/lockDetail/lockSet/faceUnlock/faceUnlock_logic.dart';
import 'package:star_lock/tools/custom_bottom_sheet.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../tools/commonItem.dart';
import '../../../../tools/titleAppBar.dart';
import '../../../../translations/trans_lib.dart';
class FaceUnlockPage extends StatefulWidget {
const FaceUnlockPage({Key? key}) : super(key: key);
@override
State<FaceUnlockPage> createState() => _FaceUnlockPageState();
}
class _FaceUnlockPageState extends State<FaceUnlockPage> {
final logic = Get.put(FaceUnlockLogic());
final state = Get.find<FaceUnlockLogic>().state;
@override
void initState() {
super.initState();
logic.getLockSettingInfoData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.faceUnlocksSet!.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Obx(() => Column(
children: [
Container(
margin: EdgeInsets.only(left: 20.w),
child: CommonItem(
leftTitel: TranslationLoader.lanKeys!.faceUnlocks!.tr,
rightTitle: "",
allHeight: 70.h,
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, height: 50.h, child: _switch(1))),
),
Container(
margin: EdgeInsets.only(left: 20.w),
child: CommonItem(
leftTitel: TranslationLoader
.lanKeys!.automaticBrighteningScreen!.tr,
rightTitle: "",
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w, height: 50.h, child: _switch(2))),
),
_buildSubTitleItem(
TranslationLoader.lanKeys!.sensingDistance!.tr,
TranslationLoader.lanKeys!.sensingDistanceTip!.tr,
state.senseDistance.value, () {
_openBottomItemSheet(state.senseDistanceList.value, 0);
}),
SizedBox(
height: 30.h,
),
_buildSubTitleItem(
TranslationLoader.lanKeys!.preventWrongOpening!.tr,
TranslationLoader.lanKeys!.preventWrongOpeningTip!.tr,
state.antiMisoperation.value == 0
? '关闭'
: '${state.antiMisoperation.value}', () {
_openBottomItemSheet(state.antiMisoperationStrList.value, 1);
}),
Expanded(
child: SizedBox(
height: 30.h,
)),
_buildTipsView(),
SizedBox(
height: 60.h,
)
],
)));
}
Widget _buildSubTitleItem(
String leftStr, String subTitle, String rightStr, Function()? action) {
return GestureDetector(
onTap: action,
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: Colors.black),
),
),
SizedBox(
height: 10.h,
),
Container(
alignment: Alignment.centerLeft,
child: Text(
subTitle,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 20.sp, color: AppColors.btnDisableColor),
),
)
],
)),
SizedBox(
width: 20.w,
),
Text(
rightStr,
style: TextStyle(
fontSize: 22.sp, color: AppColors.darkGrayTextColor),
),
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: getIndex == 1 ? state.faceOn.value : state.autoBright.value,
onChanged: (value) {
if (getIndex == 1) {
//设置面容开锁开关
state.faceOn.value = value;
logic.updateFaceSwitch();
} else {
//设置自动亮屏开关
state.autoBright.value = value;
logic.updateFaceConfig();
}
},
);
}
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: (value) {
if (clickIndex == 0) {
//感应距离
state.senseDistance.value =
state.senseDistanceList.value[value];
logic.updateFaceSenseDistance();
} else if (clickIndex == 1) {
//防误开
state.antiMisoperation.value =
state.antiMisoperationList.value[value];
logic.updateFacePreventMisrun();
}
},
);
});
}
}