232 lines
6.7 KiB
Dart
232 lines
6.7 KiB
Dart
import 'package:flutter/cupertino.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:get/get.dart';
|
|
import 'package:flutter_native_contact_picker/flutter_native_contact_picker.dart';
|
|
|
|
import '../../../../../tools/commonItem.dart';
|
|
import '../../../../../tools/submitBtn.dart';
|
|
import '../../../../appRouters.dart';
|
|
import '../../../../translations/trans_lib.dart';
|
|
|
|
class MassSendElectronicKeyPage extends StatefulWidget {
|
|
final String type;
|
|
|
|
const MassSendElectronicKeyPage({Key? key, required this.type})
|
|
: super(key: key);
|
|
|
|
@override
|
|
State<MassSendElectronicKeyPage> createState() =>
|
|
_MassSendElectronicKeyPageState();
|
|
}
|
|
|
|
class _MassSendElectronicKeyPageState extends State<MassSendElectronicKeyPage> {
|
|
final FlutterContactPicker _contactPicker = FlutterContactPicker();
|
|
late Contact _contact;
|
|
var _selectEffectiveDate = ''; //生效时间
|
|
var _selectFailureDate = ''; //失效时间
|
|
late DateTime _effectiveDateTime;
|
|
late DateTime _failureDateTime;
|
|
late bool _isSendSuccess;
|
|
late bool _isRemote; //是否远程开锁
|
|
List _receiverList = [];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return indexChangeWidget();
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
DateTime dateTime = DateTime.now();
|
|
_effectiveDateTime = dateTime;
|
|
_failureDateTime = dateTime;
|
|
_selectEffectiveDate =
|
|
'${dateTime.year}-${dateTime.month}-${dateTime.day} ${dateTime.hour}:${dateTime.minute}'; //默认为当前时间
|
|
_selectFailureDate =
|
|
'${dateTime.year}-${dateTime.month}-${dateTime.day} ${dateTime.hour}:${dateTime.minute}'; //默认为当前时间
|
|
_isSendSuccess = false;
|
|
_isRemote = false;
|
|
}
|
|
|
|
Widget indexChangeWidget() {
|
|
switch (int.parse(widget.type)) {
|
|
case 0:
|
|
{
|
|
// 限时
|
|
return Column(
|
|
children: [
|
|
keyInfoWidget(),
|
|
keyTimeWidget(),
|
|
remoteUnlockingWidget(),
|
|
keyBottomWidget()
|
|
],
|
|
);
|
|
}
|
|
case 1:
|
|
{
|
|
// 永久
|
|
return Column(
|
|
children: [
|
|
keyInfoWidget(),
|
|
remoteUnlockingWidget(),
|
|
keyBottomWidget()
|
|
],
|
|
);
|
|
}
|
|
case 2:
|
|
{
|
|
// 单次
|
|
return Column(
|
|
children: [
|
|
keyInfoWidget(),
|
|
periodValidityWidget(),
|
|
remoteUnlockingWidget(),
|
|
keyBottomWidget()
|
|
],
|
|
);
|
|
}
|
|
default:
|
|
return Container();
|
|
}
|
|
}
|
|
|
|
// 顶部钥匙信息widget
|
|
Widget keyInfoWidget() {
|
|
return Column(
|
|
children: [
|
|
Container(height: 10.h),
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.receiver!.tr,
|
|
rightTitle: _receiverList.isEmpty
|
|
? TranslationLoader.lanKeys!.pleaseAdd!.tr
|
|
: _receiverList.length.toString(),
|
|
isHaveLine: true,
|
|
isHaveDirection: true,
|
|
action: () {
|
|
Navigator.pushNamed(context, Routers.massSendReceiverPage)
|
|
.then((value) {
|
|
if (value != null) {
|
|
value as Map<String, dynamic>;
|
|
_receiverList = value['lockUserList'];
|
|
|
|
setState(() {});
|
|
}
|
|
});
|
|
}),
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.lock!.tr,
|
|
rightTitle: TranslationLoader.lanKeys!.pleaseSelet!.tr,
|
|
isHaveDirection: true,
|
|
action: () {
|
|
Navigator.pushNamed(context, Routers.massSendLockGroupPage);
|
|
}),
|
|
Container(height: 10.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 生效失效时间
|
|
Widget keyTimeWidget() {
|
|
return Column(
|
|
children: [
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr,
|
|
rightTitle: _selectEffectiveDate,
|
|
isHaveLine: true,
|
|
isHaveDirection: true,
|
|
action: () {
|
|
Pickers.showDatePicker(context, mode: DateMode.YMDHM,
|
|
onConfirm: (p) {
|
|
setState(() {
|
|
_selectEffectiveDate =
|
|
'${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}';
|
|
_effectiveDateTime = DateTime.parse(_selectEffectiveDate);
|
|
});
|
|
});
|
|
}),
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.failureTime!.tr,
|
|
rightTitle: _selectFailureDate,
|
|
isHaveDirection: true,
|
|
action: () {
|
|
Pickers.showDatePicker(context, mode: DateMode.YMDHM,
|
|
onConfirm: (p) {
|
|
setState(() {
|
|
_selectFailureDate =
|
|
'${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}';
|
|
_failureDateTime = DateTime.parse(_selectFailureDate);
|
|
});
|
|
});
|
|
}),
|
|
Container(height: 10.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 远程开锁
|
|
Widget remoteUnlockingWidget() {
|
|
return Column(
|
|
children: [
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.remoteUnlockingAllowed!.tr,
|
|
rightTitle: "",
|
|
isHaveRightWidget: true,
|
|
rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch()),
|
|
action: () {}),
|
|
Container(height: 40.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 有效期
|
|
Widget periodValidityWidget() {
|
|
return Column(
|
|
children: [
|
|
CommonItem(
|
|
leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr,
|
|
rightTitle: "",
|
|
isHaveDirection: true,
|
|
action: () {
|
|
Navigator.pushNamed(
|
|
context, Routers.electronicKeyPeriodValidityPage);
|
|
}),
|
|
Container(height: 10.h),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget keyBottomWidget() {
|
|
return Column(
|
|
children: [
|
|
SubmitBtn(
|
|
btnName: TranslationLoader.lanKeys!.send!.tr,
|
|
onClick: () {
|
|
// Navigator.pushNamed(context, Routers.nearbyLockPage);
|
|
}),
|
|
],
|
|
);
|
|
}
|
|
|
|
CupertinoSwitch _switch() {
|
|
return CupertinoSwitch(
|
|
activeColor: CupertinoColors.activeBlue,
|
|
trackColor: CupertinoColors.systemGrey5,
|
|
thumbColor: CupertinoColors.white,
|
|
value: _isRemote,
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_isRemote = !_isRemote;
|
|
});
|
|
},
|
|
);
|
|
}
|
|
|
|
String intToStr(int v) {
|
|
return (v < 10) ? "0$v" : "$v";
|
|
}
|
|
}
|