2024-08-27 11:08:44 +08:00

190 lines
6.5 KiB
Dart
Executable File

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/appRouters.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_state.dart';
import 'package:star_lock/tools/commonItem.dart';
import 'package:star_lock/tools/pickers/pickers.dart';
import 'package:star_lock/tools/pickers/style/default_style.dart';
import 'package:star_lock/tools/showCupertinoAlertView.dart';
import 'package:star_lock/tools/storage.dart';
import 'package:star_lock/tools/submitBtn.dart';
import '../../../../../app_settings/app_colors.dart';
import '../../../../../tools/titleAppBar.dart';
import 'nDaysUnopened_logic.dart';
class NDaysUnopenedPage extends StatefulWidget {
const NDaysUnopenedPage({Key? key}) : super(key: key);
@override
State<NDaysUnopenedPage> createState() => _NDaysUnopenedPageState();
}
class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
final NDaysUnopenedLogic logic = Get.put(NDaysUnopenedLogic());
final NDaysUnopenedState state = Get.find<NDaysUnopenedLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: 'N天未开门'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor,
),
body: Padding(
padding: EdgeInsets.all(30.w),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Text(
'经过以上设定的时间,锁没有被开启,系统会给指定对象发送提醒消息,该功能需要锁联网'.tr,
style: TextStyle(
fontSize: 20.sp, color: AppColors.darkGrayTextColor),
),
),
],
),
SizedBox(height: 20.h),
CommonItem(
leftTitel: 'N天未开门提醒'.tr,
rightTitle: '',
isHaveLine: true,
isHaveDirection: false,
isHaveRightWidget: true,
rightWidget: Obx(_unOpenDoorSwitch),
),
Obx(_buildOpenNoticeWidget),
Expanded(child: Container()),
SubmitBtn(
btnName: '保存'.tr,
onClick: () async {
final bool? isVip = await Storage.getBool(saveIsVip);
if (isVip == false) {
ShowCupertinoAlertView().advancedFeatureAlert();
} else {
logic.lockNoticeSettingAccountList();
}
},
),
SizedBox(height: 60.h),
],
),
),
);
}
Widget _buildOpenNoticeWidget() {
return Visibility(
visible: state.isUnOpenNotice.value,
child: Column(
children: <Widget>[
CommonItem(
leftTitel: '未开门时间'.tr,
rightTitle: '${state.unOpenDoorTime.value}' + ''.tr,
isHaveLine: true,
isHaveRightWidget: false,
isHaveDirection: true,
action: () {
_openBottomItemSheet(context, state.unopenDoorTimeList);
},
),
SizedBox(height: 20.h),
GestureDetector(
onTap: () {
Get.toNamed(Routers.notificationModePage,
arguments: <String, MsgNoticeData>{
'msgNoticeInfo': state.msgNoticeInfo.value
})?.then((val) {
if (val != null) {
state.emailListStr.value = logic.getEmailListStr(val);
state.phontListStr.value = logic.getPhoneListStr(val);
}
});
},
child: Container(
color: Colors.white,
margin: EdgeInsets.only(bottom: 10.h),
child: Column(
children: <Widget>[
CommonItem(
leftTitel: '提醒方式'.tr,
rightTitle: '',
isHaveLine: false,
isHaveRightWidget: false,
isHaveDirection: true,
),
_buildNotifyContain('APP推送'.tr, '管理员'.tr),
if (state.emailListStr.value.isNotEmpty)
_buildNotifyContain('邮件提醒'.tr, state.emailListStr.value),
if (state.phontListStr.value.isNotEmpty)
_buildNotifyContain('短信提醒'.tr, state.phontListStr.value),
],
),
),
),
],
),
);
}
Widget _buildNotifyContain(String notifyTitle, String notifyContent) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 12.h),
margin: EdgeInsets.symmetric(vertical: 10.h, horizontal: 20.w),
decoration: BoxDecoration(
color: AppColors.mainBackgroundColor,
borderRadius: BorderRadius.circular(6.0.w),
),
child: Row(
children: <Widget>[
Text(
notifyTitle,
style: TextStyle(color: Colors.black, fontSize: 20.sp),
),
Expanded(child: Container()),
Text(
notifyContent,
textAlign: TextAlign.end,
style: TextStyle(
color: AppColors.placeholderTextColor, fontSize: 20.sp),
),
],
),
);
}
CupertinoSwitch _unOpenDoorSwitch() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: state.isUnOpenNotice.value,
onChanged: (bool value) {
state.isUnOpenNotice.value = value;
if (!state.isUnOpenNotice.value) {
state.msgNoticeInfo.value = MsgNoticeData();
}
},
);
}
// 底部选择pickerView
void _openBottomItemSheet(BuildContext context, List dataList) {
Pickers.showSinglePicker(context,
data: dataList,
pickerStyle: DefaultPickerStyle(), onConfirm: (p, int position) {
state.unOpenDoorTime.value =
int.parse(state.unopenDoorTimeList[position].replaceAll('', ''));
});
}
}