193 lines
6.2 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
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.faceUnlocksSet!.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Column(
children: [
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))),
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, () {
_openBottomItemSheet(state.antiMisoperationList.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),
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) {
setState(() {
if (getIndex == 1) {
state.faceOn.value = value;
} else {
state.autoBright.value = value;
}
});
},
);
}
Future _openBottomItemSheet(
List<String> 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];
} else if (clickIndex == 1) {
//防误开
state.antiMisoperation.value =
state.antiMisoperationList.value[value];
}
setState(() {});
},
);
});
}
}