392 lines
13 KiB
Dart
Raw Normal View History

import 'package:flutter/cupertino.dart';
2023-07-10 17:50:31 +08:00
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
2023-07-10 17:50:31 +08:00
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
2024-07-26 14:12:26 +08:00
import 'package:star_lock/main/lockDetail/lockSet/normallyOpenMode/normallyOpenMode_state.dart';
import 'package:star_lock/tools/pickers/pickers.dart';
import 'package:star_lock/tools/pickers/time_picker/model/date_mode.dart';
import 'package:star_lock/tools/pickers/time_picker/model/pduration.dart';
2023-07-10 17:50:31 +08:00
import '../../../../app_settings/app_colors.dart';
import '../../../../tools/appRouteObserver.dart';
2023-07-10 17:50:31 +08:00
import '../../../../tools/commonItem.dart';
import '../../../../tools/submitBtn.dart';
import '../../../../tools/titleAppBar.dart';
2023-09-07 18:36:16 +08:00
import 'normallyOpenMode_logic.dart';
2023-07-10 17:50:31 +08:00
class NormallyOpenModePage extends StatefulWidget {
2023-07-15 15:11:28 +08:00
const NormallyOpenModePage({Key? key}) : super(key: key);
2023-07-10 17:50:31 +08:00
@override
State<NormallyOpenModePage> createState() => _NormallyOpenModePageState();
}
2024-07-26 14:12:26 +08:00
class _NormallyOpenModePageState extends State<NormallyOpenModePage> with RouteAware {
final NormallyOpenModeLogic logic = Get.put(NormallyOpenModeLogic());
final NormallyOpenModeState state = Get.find<NormallyOpenModeLogic>().state;
2023-09-07 18:36:16 +08:00
2023-07-10 17:50:31 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
2024-07-26 14:12:26 +08:00
barTitle: '常开模式'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
2023-09-07 18:36:16 +08:00
body: Obx(() => ListView(
2024-07-26 14:12:26 +08:00
children: <Widget>[
CommonItem(
2024-07-26 14:12:26 +08:00
leftTitel: '常开模式'.tr,
2024-07-26 09:21:22 +08:00
rightTitle: '',
isHaveLine: false,
isHaveRightWidget: true,
rightWidget: SizedBox(
width: 60.w,
height: 50.h,
child: _normallyOpenModeSwitch())),
SizedBox(
height: 1.h,
),
Container(
padding: EdgeInsets.only(
left: 30.w, right: 30.w, top: 20.w, bottom: 20.w),
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
2024-07-26 14:12:26 +08:00
children: <Widget>[
Expanded(
2024-08-27 11:08:44 +08:00
child: Text('你可以设置多个常开时间段,在设置的时间段内,锁被打开后一直处于打开的状态。'.tr,
2023-09-07 18:36:16 +08:00
style: TextStyle(fontSize: 20.sp),
)),
2023-07-10 17:50:31 +08:00
],
),
),
SizedBox(
height: 10.h,
),
Visibility(
visible: state.isOpenNormallyOpenMode.value,
child: Container(
color: Colors.white,
child: Column(
2024-07-26 14:12:26 +08:00
children: <Widget>[
// CommonItem(
// leftTitel: TranslationLoader.lanKeys!.automaticUnLock!.tr,
// rightTitle: "",
// isHaveLine: false,
// isHaveRightWidget: true,
// rightWidget:
// SizedBox(width: 60.w, height: 50.h, child: _autoUnlockSwitch())),
// Container(
// height: 1.h,
// color: AppColors.mainBackgroundColor,
// ),
// Container(
// padding: EdgeInsets.only(
// left: 30.w, right: 30.w, top: 20.w, bottom: 20.w),
// color: Colors.white,
// child: Row(
// mainAxisAlignment: MainAxisAlignment.start,
// children: [
// Expanded(
// child: Text(
// TranslationLoader.lanKeys!.automaticUnLockTip!.tr,
// style: TextStyle(fontSize: 20.sp),
// )),
// ],
// ),
// ),
// Container(
// height: 10.h,
// color: AppColors.mainBackgroundColor,
// ),
topWidget(),
SizedBox(
height: 10.h,
),
bottomWidget()
],
),
)),
2023-12-16 11:20:36 +08:00
Obx(() => Container(
margin:
EdgeInsets.only(left: 20.w, right: 20.w, top: 30.h),
child: state.isJustForShow.value == true
? Container()
: SubmitBtn(
2024-07-31 17:24:30 +08:00
btnName: '保存'.tr,
onClick: () {
logic.sendAutoLock();
}),
)),
],
)));
2023-07-10 17:50:31 +08:00
}
Widget topWidget() {
2023-07-10 17:50:31 +08:00
return Container(
height: 160.h,
2023-07-10 17:50:31 +08:00
width: 1.sw,
color: Colors.white,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2024-07-26 14:12:26 +08:00
children: <Widget>[
2023-07-10 17:50:31 +08:00
Container(
height: 60.h,
// color: Colors.red,
padding: EdgeInsets.only(left: 30.w, top: 15.h),
child: Text(
2024-07-26 14:12:26 +08:00
'常开日期'.tr,
style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600))),
2023-07-10 17:50:31 +08:00
Container(
height: 100.h,
padding: EdgeInsets.only(left: 10.w, right: 10.w, bottom: 10.h),
2023-07-10 17:50:31 +08:00
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 7, childAspectRatio: 1.0),
2023-07-10 17:50:31 +08:00
itemCount: 7,
physics: const NeverScrollableScrollPhysics(),
2024-07-26 14:12:26 +08:00
itemBuilder: (BuildContext context, int index) {
2023-09-07 18:36:16 +08:00
index += 1;
2023-07-10 17:50:31 +08:00
return btnItem(index);
})),
2023-07-10 17:50:31 +08:00
],
),
);
}
Widget btnItem(int index) {
2023-07-10 17:50:31 +08:00
String dateStr;
switch (index) {
case 1:
2024-07-26 09:21:22 +08:00
dateStr = '简写周一'.tr;
2023-07-10 17:50:31 +08:00
break;
case 2:
2024-07-26 09:21:22 +08:00
dateStr = '简写周二'.tr;
2023-07-10 17:50:31 +08:00
break;
case 3:
2024-07-26 09:21:22 +08:00
dateStr = '简写周三'.tr;
2023-07-10 17:50:31 +08:00
break;
case 4:
2024-07-26 09:21:22 +08:00
dateStr = '简写周四'.tr;
2023-07-10 17:50:31 +08:00
break;
case 5:
2024-07-26 09:21:22 +08:00
dateStr = '简写周五'.tr;
2023-07-10 17:50:31 +08:00
break;
case 6:
2024-07-26 09:21:22 +08:00
dateStr = '简写周六'.tr;
2023-07-10 17:50:31 +08:00
break;
2023-09-07 18:36:16 +08:00
case 7:
2024-07-26 09:21:22 +08:00
dateStr = '简写周日'.tr;
2023-09-07 18:36:16 +08:00
break;
2023-07-10 17:50:31 +08:00
default:
2024-07-26 09:21:22 +08:00
dateStr = '';
2023-07-10 17:50:31 +08:00
break;
}
return GestureDetector(
2023-09-07 18:36:16 +08:00
onTap: () {
if (state.isJustForShow.value == true) {
2024-01-23 18:37:03 +08:00
return;
}
if (state.weekDays.value.contains(index)) {
2023-09-07 18:36:16 +08:00
state.weekDays.value.remove(index);
} else {
2023-09-07 18:36:16 +08:00
state.weekDays.value.add(index);
}
state.weekDays.value.sort();
setState(() {});
},
child: Obx(() => Container(
width: 40.w,
height: 40.w,
margin: EdgeInsets.all(10.w),
decoration: BoxDecoration(
color: state.weekDays.value.contains(index)
? AppColors.mainColor
: Colors.white,
border: Border.all(width: 1, color: AppColors.btnDisableColor),
borderRadius: BorderRadius.circular(30.w),
),
child: Center(
child: Text(
2023-09-07 18:36:16 +08:00
dateStr,
style: TextStyle(
fontSize: 20.sp,
color: state.weekDays.value.contains(index)
? Colors.white
: AppColors.darkGrayTextColor),
2023-09-07 18:36:16 +08:00
)),
)),
2023-07-10 17:50:31 +08:00
);
}
Widget bottomWidget() {
2023-07-10 17:50:31 +08:00
return Column(
2024-07-26 14:12:26 +08:00
children: <Widget>[
Container(
color: AppColors.mainBackgroundColor,
height: 10.h,
),
2023-09-07 18:36:16 +08:00
Obx(() => CommonItem(
2024-07-26 14:12:26 +08:00
leftTitel: '常开时间'.tr,
2024-07-26 09:21:22 +08:00
rightTitle: '',
isHaveLine: true,
isHaveRightWidget: true,
rightWidget: GestureDetector(
2023-09-07 18:36:16 +08:00
onTap: () {
// 选择全天模式
if (state.isJustForShow.value == true) {
2024-01-23 18:37:03 +08:00
return;
}
if (state.isAllDay.value == 1) {
state.isAllDay.value = 0;
} else {
2023-09-07 18:36:16 +08:00
state.isAllDay.value = 1;
}
setState(() {});
},
child: Row(
2024-07-26 14:12:26 +08:00
children: <Widget>[
Text(
2024-07-31 17:24:30 +08:00
'全天'.tr,
style: TextStyle(fontSize: 22.sp),
),
SizedBox(
width: 5.w,
),
Image.asset(
state.isAllDay.value == 1
2024-01-23 17:48:06 +08:00
? 'images/icon_round_select.png'
2024-01-23 17:29:18 +08:00
: 'images/icon_round_unSelect.png',
width: 30.w,
height: 30.w,
),
],
),
2023-09-07 18:36:16 +08:00
))),
2023-07-10 17:50:31 +08:00
Visibility(
visible: true,
child: Container(
color: Colors.white,
child: Column(
2024-07-26 14:12:26 +08:00
children: <Widget>[
2023-09-07 18:36:16 +08:00
Obx(() => CommonItem(
leftTitel:
2024-07-26 14:12:26 +08:00
'开始时间'.tr,
2023-09-07 18:36:16 +08:00
rightTitle: state.beginTime.value,
isHaveDirection: true,
isHaveLine: true,
2023-09-07 18:36:16 +08:00
action: () {
if (state.isJustForShow.value == true) {
2024-01-23 18:37:03 +08:00
return;
}
PDuration selectDate = PDuration.parse(
DateTime.tryParse(state.beginTime.value));
Pickers.showDatePicker(context,
selectDate: selectDate,
2024-07-26 14:12:26 +08:00
mode: DateMode.HM, onConfirm: (PDuration p) {
setState(() {
state.beginTimeMinute.value =
p.hour! * 60 + p.minute!;
2024-07-26 09:21:22 +08:00
state.beginTime.value = '${p.hour}:${p.minute!}';
});
});
2023-09-07 18:36:16 +08:00
})),
Obx(() => CommonItem(
2024-07-26 14:12:26 +08:00
leftTitel: '结束时间'.tr,
2023-09-07 18:36:16 +08:00
rightTitle: state.endTime.value,
isHaveDirection: true,
2023-09-07 18:36:16 +08:00
action: () {
if (state.isJustForShow.value == true) {
2024-01-23 18:37:03 +08:00
return;
}
PDuration selectDate = PDuration.parse(
DateTime.tryParse(state.endTime.value));
Pickers.showDatePicker(context,
selectDate: selectDate,
2024-07-26 14:12:26 +08:00
mode: DateMode.HM, onConfirm: (PDuration p) {
setState(() {
state.endTimeMinute.value =
p.hour! * 60 + p.minute!;
2024-07-26 09:21:22 +08:00
state.endTime.value = '${p.hour}:${p.minute!}';
});
});
2023-09-07 18:36:16 +08:00
})),
2023-07-10 17:50:31 +08:00
Container(height: 10.h),
],
),
)),
2023-07-10 17:50:31 +08:00
],
);
}
2023-09-07 18:36:16 +08:00
CupertinoSwitch _normallyOpenModeSwitch() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: state.isOpenNormallyOpenMode.value,
onChanged: state.isJustForShow.value == true
? null
2024-07-26 14:12:26 +08:00
: (bool value) {
setState(() {
state.isOpenNormallyOpenMode.value = value;
});
},
2023-09-07 18:36:16 +08:00
);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
2024-04-16 18:33:24 +08:00
// 路由订阅
AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!);
}
@override
void dispose() {
2024-04-16 18:33:24 +08:00
// 取消路由订阅
AppRouteObserver().routeObserver.unsubscribe(this);
super.dispose();
}
/// 从上级界面进入 当前界面即将出现
@override
void didPush() {
super.didPush();
state.ifCurrentScreen.value = true;
}
/// 返回上一个界面 当前界面即将消失
@override
void didPop() {
super.didPop();
logic.cancelBlueConnetctToastTimer();
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0;
}
/// 从下级返回 当前界面即将出现
@override
void didPopNext() {
super.didPopNext();
state.ifCurrentScreen.value = true;
}
/// 进入下级界面 当前界面即将消失
@override
void didPushNext() {
super.didPushNext();
logic.cancelBlueConnetctToastTimer();
if (EasyLoading.isShow) EasyLoading.dismiss(animation: true);
state.ifCurrentScreen.value = false;
state.sureBtnState.value = 0;
}
2023-07-10 17:50:31 +08:00
}