1,新增有效期相关自定义数据块实体类
2,处理循环发送钥匙的有效期逻辑
This commit is contained in:
parent
8b426ade6c
commit
2a707ad4b3
@ -37,7 +37,6 @@ class _SeletCountryRegionPageState extends State<SeletCountryRegionPage> {
|
|||||||
CountryRegionEntity entity = await ApiRepository.to.getCountryRegion('1');
|
CountryRegionEntity entity = await ApiRepository.to.getCountryRegion('1');
|
||||||
countriesList.clear();
|
countriesList.clear();
|
||||||
if (entity.errorCode!.codeIsSuccessful) {
|
if (entity.errorCode!.codeIsSuccessful) {
|
||||||
print("国家/地区json文件成功啦啦啦啦啦");
|
|
||||||
countriesList.addAll(entity.dataList!);
|
countriesList.addAll(entity.dataList!);
|
||||||
_handleList(countriesList);
|
_handleList(countriesList);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
class KeyPeriodValidityModel {
|
||||||
|
late String validityText; //有效期时间
|
||||||
|
late int validityIndex; //有效期的index
|
||||||
|
late bool isValidity; //是否选中为有效
|
||||||
|
|
||||||
|
KeyPeriodValidityModel(
|
||||||
|
this.validityText, this.validityIndex, this.isValidity);
|
||||||
|
|
||||||
|
KeyPeriodValidityModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
validityText = json['validityText'];
|
||||||
|
validityIndex = json['validityIndex'];
|
||||||
|
isValidity = json['isValidity'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['validityText'] = validityText;
|
||||||
|
data['validityIndex'] = validityIndex;
|
||||||
|
data['isValidity'] = isValidity;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,10 @@
|
|||||||
|
import 'package:date_format/date_format.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_pickers/pickers.dart';
|
||||||
|
import 'package:flutter_pickers/time_picker/model/date_mode.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyPeriodValidity/KeyPeriodValidityModel.dart';
|
||||||
|
|
||||||
import '../../../../app_settings/app_colors.dart';
|
import '../../../../app_settings/app_colors.dart';
|
||||||
import '../../../../tools/commonItem.dart';
|
import '../../../../tools/commonItem.dart';
|
||||||
@ -18,6 +22,34 @@ class ElectronicKeyPeriodValidityPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _ElectronicKeyPeriodValidityPageState
|
class _ElectronicKeyPeriodValidityPageState
|
||||||
extends State<ElectronicKeyPeriodValidityPage> {
|
extends State<ElectronicKeyPeriodValidityPage> {
|
||||||
|
List validityTextList = [
|
||||||
|
TranslationLoader.lanKeys!.sundayShort!.tr,
|
||||||
|
TranslationLoader.lanKeys!.mondayShort!.tr,
|
||||||
|
TranslationLoader.lanKeys!.tuesdayShort!.tr,
|
||||||
|
TranslationLoader.lanKeys!.wednesdayShort!.tr,
|
||||||
|
TranslationLoader.lanKeys!.thursdayShort!.tr,
|
||||||
|
TranslationLoader.lanKeys!.fridayShort!.tr,
|
||||||
|
TranslationLoader.lanKeys!.saturdayShort!.tr
|
||||||
|
];
|
||||||
|
List validityDataList = []; //自定义数据块
|
||||||
|
List selectIndexList = []; //选中的有效期数组
|
||||||
|
String _effectiveTime = '';
|
||||||
|
String _failureTime = '';
|
||||||
|
|
||||||
|
String _effectiveDate = '';
|
||||||
|
String _failureDate = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
for (var i = 0; i < validityTextList.length; i++) {
|
||||||
|
KeyPeriodValidityModel model =
|
||||||
|
KeyPeriodValidityModel(validityTextList[i], i, false);
|
||||||
|
validityDataList.add(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -26,12 +58,9 @@ class _ElectronicKeyPeriodValidityPageState
|
|||||||
barTitle: TranslationLoader.lanKeys!.periodValidity!.tr,
|
barTitle: TranslationLoader.lanKeys!.periodValidity!.tr,
|
||||||
haveBack: true,
|
haveBack: true,
|
||||||
backgroundColor: AppColors.mainColor),
|
backgroundColor: AppColors.mainColor),
|
||||||
body: Column(
|
body: ListView(
|
||||||
children: [
|
children: [
|
||||||
topWidget(),
|
topWidget(),
|
||||||
// SizedBox(
|
|
||||||
// height: 1.h,
|
|
||||||
// ),
|
|
||||||
Container(
|
Container(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
height: 10.h,
|
height: 10.h,
|
||||||
@ -68,56 +97,44 @@ class _ElectronicKeyPeriodValidityPageState
|
|||||||
itemCount: 7,
|
itemCount: 7,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return btnItem(index);
|
KeyPeriodValidityModel model = validityDataList[index];
|
||||||
|
return btnItem(model);
|
||||||
}))
|
}))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget btnItem(int index) {
|
Widget btnItem(KeyPeriodValidityModel model) {
|
||||||
String dateStr;
|
|
||||||
switch (index) {
|
|
||||||
case 0:
|
|
||||||
dateStr = TranslationLoader.lanKeys!.sundayShort!.tr;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
dateStr = TranslationLoader.lanKeys!.mondayShort!.tr;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
dateStr = TranslationLoader.lanKeys!.tuesdayShort!.tr;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
dateStr = TranslationLoader.lanKeys!.wednesdayShort!.tr;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
dateStr = TranslationLoader.lanKeys!.thursdayShort!.tr;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
dateStr = TranslationLoader.lanKeys!.fridayShort!.tr;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
dateStr = TranslationLoader.lanKeys!.saturdayShort!.tr;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dateStr = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
model.isValidity = !model.isValidity;
|
||||||
|
if (model.isValidity) {
|
||||||
|
selectIndexList.add(model.validityIndex);
|
||||||
|
} else {
|
||||||
|
selectIndexList.remove(model.validityIndex);
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 40.w,
|
width: 40.w,
|
||||||
height: 40.w,
|
height: 40.w,
|
||||||
margin: EdgeInsets.all(10.w),
|
margin: EdgeInsets.all(10.w),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
// color: Colors.blue,
|
color: selectIndexList.contains(model.validityIndex)
|
||||||
|
? Colors.blue
|
||||||
|
: Colors.white,
|
||||||
border: Border.all(width: 1, color: AppColors.greyBackgroundColor),
|
border: Border.all(width: 1, color: AppColors.greyBackgroundColor),
|
||||||
borderRadius: BorderRadius.circular(30.w),
|
borderRadius: BorderRadius.circular(30.w),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
dateStr,
|
model.validityText,
|
||||||
style: TextStyle(fontSize: 20.sp, color: AppColors.darkGrayTextColor),
|
style: TextStyle(
|
||||||
|
fontSize: 20.sp,
|
||||||
|
color: selectIndexList.contains(model.validityIndex)
|
||||||
|
? Colors.white
|
||||||
|
: AppColors.darkGrayTextColor),
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -128,27 +145,63 @@ class _ElectronicKeyPeriodValidityPageState
|
|||||||
children: [
|
children: [
|
||||||
CommonItem(
|
CommonItem(
|
||||||
leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr,
|
leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr,
|
||||||
rightTitle: "",
|
rightTitle: _effectiveTime,
|
||||||
isHaveDirection: true,
|
isHaveDirection: true,
|
||||||
isHaveLine: true,
|
isHaveLine: true,
|
||||||
action: () {}),
|
action: () {
|
||||||
|
Pickers.showDatePicker(context, mode: DateMode.HM,
|
||||||
|
onConfirm: (p) {
|
||||||
|
DateTime getPTime = DateTime.parse(
|
||||||
|
'${intToStr(p.hour!)}:${intToStr(p.minute!)}');
|
||||||
|
_effectiveTime = formatDate(getPTime, [HH, ':', nn]);
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
}),
|
||||||
CommonItem(
|
CommonItem(
|
||||||
leftTitel: TranslationLoader.lanKeys!.failureTime!.tr,
|
leftTitel: TranslationLoader.lanKeys!.failureTime!.tr,
|
||||||
rightTitle: "",
|
rightTitle: _failureTime,
|
||||||
isHaveDirection: true,
|
isHaveDirection: true,
|
||||||
action: () {}),
|
action: () {
|
||||||
|
Pickers.showDatePicker(context, mode: DateMode.HM,
|
||||||
|
onConfirm: (p) {
|
||||||
|
DateTime getPTime = DateTime.parse(
|
||||||
|
'${intToStr(p.hour!)}:${intToStr(p.minute!)}');
|
||||||
|
_failureTime = formatDate(getPTime, [HH, ':', nn]);
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
}),
|
||||||
Container(height: 10.h),
|
Container(height: 10.h),
|
||||||
CommonItem(
|
CommonItem(
|
||||||
leftTitel: TranslationLoader.lanKeys!.effectiveDate!.tr,
|
leftTitel: TranslationLoader.lanKeys!.effectiveDate!.tr,
|
||||||
rightTitle: "",
|
rightTitle: _effectiveDate,
|
||||||
isHaveDirection: true,
|
isHaveDirection: true,
|
||||||
isHaveLine: true,
|
isHaveLine: true,
|
||||||
action: () {}),
|
action: () {
|
||||||
|
Pickers.showDatePicker(context, mode: DateMode.YMD,
|
||||||
|
onConfirm: (p) {
|
||||||
|
DateTime getPTime = DateTime.parse(
|
||||||
|
'${intToStr(p.year!)}-${intToStr(p.month!)}-${intToStr(p.day!)}');
|
||||||
|
_effectiveDate = formatDate(getPTime, [yyyy, '-', mm, '-', dd]);
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
}),
|
||||||
CommonItem(
|
CommonItem(
|
||||||
leftTitel: TranslationLoader.lanKeys!.failureDate!.tr,
|
leftTitel: TranslationLoader.lanKeys!.failureDate!.tr,
|
||||||
rightTitle: "",
|
rightTitle: _failureDate,
|
||||||
isHaveDirection: true,
|
isHaveDirection: true,
|
||||||
action: () {}),
|
action: () {
|
||||||
|
Pickers.showDatePicker(context, mode: DateMode.YMD,
|
||||||
|
onConfirm: (p) {
|
||||||
|
DateTime getPTime = DateTime.parse(
|
||||||
|
'${intToStr(p.year!)}-${intToStr(p.month!)}-${intToStr(p.day!)}');
|
||||||
|
_failureDate = formatDate(getPTime, [yyyy, '-', mm, '-', dd]);
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
}),
|
||||||
Container(height: 40.h),
|
Container(height: 40.h),
|
||||||
SubmitBtn(
|
SubmitBtn(
|
||||||
btnName: TranslationLoader.lanKeys!.sure!.tr,
|
btnName: TranslationLoader.lanKeys!.sure!.tr,
|
||||||
@ -161,4 +214,8 @@ class _ElectronicKeyPeriodValidityPageState
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String intToStr(int v) {
|
||||||
|
return (v < 10) ? "0$v" : "$v";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user