import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; 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'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/commonItem.dart'; import '../../../../tools/submitBtn.dart'; import '../../../../tools/titleAppBar.dart'; import 'normallyOpenMode_logic.dart'; class NormallyOpenModePage extends StatefulWidget { const NormallyOpenModePage({Key? key}) : super(key: key); @override State createState() => _NormallyOpenModePageState(); } class _NormallyOpenModePageState extends State with RouteAware { final NormallyOpenModeLogic logic = Get.put(NormallyOpenModeLogic()); final NormallyOpenModeState state = Get.find().state; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: '常开模式'.tr, haveBack: true, backgroundColor: AppColors.mainColor), body: Obx(() => ListView( children: [ CommonItem( leftTitel: '常开模式'.tr, 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, children: [ Expanded( child: Text('你可以设置多个常开时间段,在设置的时间段内,锁被打开后一直处于打开的状态。'.tr, style: TextStyle(fontSize: 20.sp), )), ], ), ), SizedBox( height: 10.h, ), Visibility( visible: state.isOpenNormallyOpenMode.value, child: Container( color: Colors.white, child: Column( children: [ // 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() ], ), )), Obx(() => Container( margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 30.h), child: state.isJustForShow.value == true ? Container() : SubmitBtn( btnName: '保存'.tr, onClick: () { logic.sendAutoLock(); }), )), ], ))); } Widget topWidget() { return Container( height: 160.h, width: 1.sw, color: Colors.white, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( height: 60.h, // color: Colors.red, padding: EdgeInsets.only(left: 30.w, top: 15.h), child: Text( '常开日期'.tr, style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600))), Container( height: 100.h, padding: EdgeInsets.only(left: 10.w, right: 10.w, bottom: 10.h), child: GridView.builder( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 7, childAspectRatio: 1.0), itemCount: 7, physics: const NeverScrollableScrollPhysics(), itemBuilder: (BuildContext context, int index) { index += 1; return btnItem(index); })), ], ), ); } Widget btnItem(int index) { String dateStr; switch (index) { case 1: dateStr = '简写周一'.tr; break; case 2: dateStr = '简写周二'.tr; break; case 3: dateStr = '简写周三'.tr; break; case 4: dateStr = '简写周四'.tr; break; case 5: dateStr = '简写周五'.tr; break; case 6: dateStr = '简写周六'.tr; break; case 7: dateStr = '简写周日'.tr; break; default: dateStr = ''; break; } return GestureDetector( onTap: () { if (state.isJustForShow.value == true) { return; } if (state.weekDays.value.contains(index)) { state.weekDays.value.remove(index); } else { 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( dateStr, style: TextStyle( fontSize: 20.sp, color: state.weekDays.value.contains(index) ? Colors.white : AppColors.darkGrayTextColor), )), )), ); } Widget bottomWidget() { return Column( children: [ Container( color: AppColors.mainBackgroundColor, height: 10.h, ), Obx(() => CommonItem( leftTitel: '常开时间'.tr, rightTitle: '', isHaveLine: true, isHaveRightWidget: true, rightWidget: GestureDetector( onTap: () { // 选择全天模式 if (state.isJustForShow.value == true) { return; } if (state.isAllDay.value == 1) { state.isAllDay.value = 0; } else { state.isAllDay.value = 1; } setState(() {}); }, child: Row( children: [ Text( '全天'.tr, style: TextStyle(fontSize: 22.sp), ), SizedBox( width: 5.w, ), Image.asset( state.isAllDay.value == 1 ? 'images/icon_round_select.png' : 'images/icon_round_unSelect.png', width: 30.w, height: 30.w, ), ], ), ))), Visibility( visible: true, child: Container( color: Colors.white, child: Column( children: [ Obx(() => CommonItem( leftTitel: '开始时间'.tr, rightTitle: state.beginTime.value, isHaveDirection: true, isHaveLine: true, action: () { if (state.isJustForShow.value == true) { return; } PDuration selectDate = PDuration.parse( DateTime.tryParse(state.beginTime.value)); Pickers.showDatePicker(context, selectDate: selectDate, mode: DateMode.HM, onConfirm: (PDuration p) { setState(() { state.beginTimeMinute.value = p.hour! * 60 + p.minute!; state.beginTime.value = '${p.hour}:${p.minute!}'; }); }); })), Obx(() => CommonItem( leftTitel: '结束时间'.tr, rightTitle: state.endTime.value, isHaveDirection: true, action: () { if (state.isJustForShow.value == true) { return; } PDuration selectDate = PDuration.parse( DateTime.tryParse(state.endTime.value)); Pickers.showDatePicker(context, selectDate: selectDate, mode: DateMode.HM, onConfirm: (PDuration p) { setState(() { state.endTimeMinute.value = p.hour! * 60 + p.minute!; state.endTime.value = '${p.hour}:${p.minute!}'; }); }); })), Container(height: 10.h), ], ), )), ], ); } CupertinoSwitch _normallyOpenModeSwitch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.isOpenNormallyOpenMode.value, onChanged: state.isJustForShow.value == true ? null : (bool value) { setState(() { state.isOpenNormallyOpenMode.value = value; }); }, ); } @override void didChangeDependencies() { super.didChangeDependencies(); // 路由订阅 AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); } @override void dispose() { // 取消路由订阅 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; } }