2023-10-07 18:55:59 +08:00

169 lines
6.2 KiB
Dart

import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../../app_settings/app_colors.dart';
import '../../../../tools/commonItem.dart';
import '../../../../tools/showBottomSheetTool.dart';
import '../../../../tools/titleAppBar.dart';
import '../../../../translations/trans_lib.dart';
import 'automaticBlocking_logic.dart';
class AutomaticBlockingPage extends StatefulWidget {
const AutomaticBlockingPage({Key? key}) : super(key: key);
@override
State<AutomaticBlockingPage> createState() => _AutomaticBlockingPageState();
}
class _AutomaticBlockingPageState extends State<AutomaticBlockingPage> {
final logic = Get.put(AutomaticBlockingLogic());
final state = Get.find<AutomaticBlockingLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.automaticBlocking!.tr,
haveBack: true,
actionsList: [
TextButton(
child: Text(
TranslationLoader.lanKeys!.save!.tr,
style: TextStyle(color: Colors.white, fontSize: 24.sp),
),
onPressed: () {
// logic.sendAutoLock();
logic.sendAutoLock();
},
),
],
backgroundColor: AppColors.mainColor),
body: ListView(
children: [
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.automaticBlocking!.tr,
rightTitle: "${state.autoLockTime}s",
isHaveLine: false,
isHaveRightWidget: true,
rightWidget:
SizedBox(width: 60.w, height: 50.h, child: _switch())),),
Container(height: 10.h,),
Builder(builder: (context) {
return Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.delayTime!.tr,
rightTitle: state.isCustomLockTime.value == true ? "自定义" : "${state.autoLockTime.value}s",
isHaveLine: false,
isHaveDirection: true,
action: () {
var list = [
"5",
"10",
"15",
"30",
"60",
TranslationLoader.lanKeys!.custom!.tr
];
ShowBottomSheetTool().showSingleRowPicker(
//上下文
context,
//默认的索引
normalIndex: 0,
title: TranslationLoader.lanKeys!.time!.tr,
cancelTitle: TranslationLoader.lanKeys!.cancel!.tr,
sureTitle: TranslationLoader.lanKeys!.sure!.tr,
//要显示的列表
//可自定义数据适配器
//adapter: PickerAdapter(),
data: list,
//选择事件的回调
clickCallBack: (int index, var str) {
if(index != 5){
state.autoLockTime.value = str.toString();
}else{
state.isCustomLockTime.value = true;
}
});
}));
}),
Container(
height: 10.h,
),
Obx(() => Visibility(
visible: state.isCustomLockTime.value,
child: Container(
color: Colors.white,
padding: EdgeInsets.only(
left: 30.w, top: 10.w, right: 30.w, bottom: 10.w),
child: Column(
children: [
Row(
children: [
Text(
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.time!.tr}(S)",
style: TextStyle(fontSize: 24.sp),
),
],
),
TextField(
//输入框一行
maxLines: 1,
controller: state.timeController,
autofocus: false,
decoration: InputDecoration(
//输入里面输入文字内边距设置
contentPadding:
const EdgeInsets.only(top: 12.0, bottom: 8.0),
hintText:
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.time!.tr}(S)",
hintStyle: TextStyle(fontSize: 24.sp),
//不需要输入框下划线
border: InputBorder.none,
),
),
Container(
height: 0.5.h,
color: Colors.grey,
),
],
),
))),
Container(
padding: EdgeInsets.all(30.w),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Text(
TranslationLoader.lanKeys!.automaticBlockingTip!.tr,
style: TextStyle(fontSize: 20.sp),
)),
],
),
)
],
));
}
CupertinoSwitch _switch() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: state.isOpen.value,
onChanged: (value) {
setState(() {
state.isOpen.value = value;
if(state.isOpen.value == false){
state.autoLockTime.value = "0";
}
});
},
);
}
}