324 lines
11 KiB
Dart
Executable File
324 lines
11 KiB
Dart
Executable File
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/main/lockMian/lockMain/lockMain_logic.dart';
|
|
|
|
import '../../../../appRouters.dart';
|
|
import '../../../../app_settings/app_colors.dart';
|
|
import '../../../../tools/EasyRefreshTool.dart';
|
|
import '../../../../tools/appRouteObserver.dart';
|
|
import '../../../../tools/keySearchWidget.dart';
|
|
import '../../../../tools/noData.dart';
|
|
import '../../../../tools/showTipView.dart';
|
|
import '../../../../tools/storage.dart';
|
|
import '../../../../tools/submitBtn.dart';
|
|
import '../../../../tools/titleAppBar.dart';
|
|
import '../../fingerprint/fingerprintList/fingerprintListData_entity.dart';
|
|
import 'remoteControlList_logic.dart';
|
|
import 'remoteControlList_state.dart';
|
|
|
|
class RemoteControlListPage extends StatefulWidget {
|
|
const RemoteControlListPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<RemoteControlListPage> createState() => _RemoteControlListPageState();
|
|
}
|
|
|
|
class _RemoteControlListPageState extends State<RemoteControlListPage> with RouteAware {
|
|
final RemoteControlListLogic logic = Get.put(RemoteControlListLogic());
|
|
final RemoteControlListState state = Get.find<RemoteControlListLogic>().state;
|
|
|
|
Future<void> getHttpData({required bool isRefresh}) async {
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
logic.getRemoteControlListData(isRefresh: isRefresh).then((FingerprintListDataEntity value) {
|
|
if (mounted) {
|
|
setState(() {});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
getHttpData(isRefresh: true);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.mainBackgroundColor,
|
|
resizeToAvoidBottomInset: false,
|
|
appBar: TitleAppBar(
|
|
barTitle: '遥控'.tr,
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
actionsList: <Widget>[
|
|
TextButton(
|
|
child: Text(
|
|
'重置'.tr,
|
|
style: TextStyle(color: Colors.white, fontSize: 24.sp),
|
|
),
|
|
onPressed: () async {
|
|
final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
|
|
if (isDemoMode == false) {
|
|
final bool isNetWork =
|
|
await logic.isConnected() ?? false;
|
|
if (!isNetWork) {
|
|
return;
|
|
}
|
|
|
|
ShowTipView().showIosTipWithContentDialog(
|
|
'重置后,该锁的遥控都将被删除哦,确认要重置吗?'.tr, () async {
|
|
state.isDeletAll = true;
|
|
state.deletKeyID = '0';
|
|
state.deletRemoteControlNo = 0;
|
|
logic.senderAddRemoteControl();
|
|
});
|
|
// showDeletAlertDialog(context);
|
|
} else {
|
|
logic.showToast('演示模式'.tr);
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
body: EasyRefreshTool(
|
|
onRefresh: () {
|
|
getHttpData(isRefresh: true);
|
|
},
|
|
onLoad: () {
|
|
getHttpData(isRefresh: false);
|
|
},
|
|
child: Column(
|
|
children: <Widget>[
|
|
KeySearchWidget(
|
|
editingController: state.searchController,
|
|
onSubmittedAction: () {
|
|
getHttpData(isRefresh: true);
|
|
},
|
|
),
|
|
SizedBox(height: 20.h),
|
|
Expanded(child: _buildMainUI()),
|
|
AddBottomWhiteBtn(
|
|
btnName: '添加遥控'.tr,
|
|
onClick: () async {
|
|
await Get.toNamed(Routers.addRemoteControlTypePage,
|
|
arguments: <String, int>{
|
|
'lockId': state.lockId.value,
|
|
'fromType': 1 // 1从添加钥匙列表进入 2从考勤添加员工入口进入
|
|
})!.then((value) => getHttpData(isRefresh: true));
|
|
// if (data != null) {
|
|
// getHttpData(isRefresh: true);
|
|
// }
|
|
},
|
|
),
|
|
SizedBox(
|
|
height: 64.h,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMainUI() {
|
|
return Obx(() => state.fingerprintItemListData.value.isNotEmpty
|
|
? SlidableAutoCloseBehavior(
|
|
child: ListView.separated(
|
|
itemCount: state.fingerprintItemListData.value.length,
|
|
itemBuilder: (BuildContext c, int index) {
|
|
final FingerprintItemData fingerprintItemData =
|
|
state.fingerprintItemListData.value[index];
|
|
return Slidable(
|
|
key: ValueKey(fingerprintItemData.fingerprintId),
|
|
endActionPane: ActionPane(
|
|
extentRatio: 0.2,
|
|
motion: const ScrollMotion(),
|
|
children: <Widget>[
|
|
SlidableAction(
|
|
onPressed: (BuildContext context) async {
|
|
final bool isNetWork =
|
|
await logic.isConnected() ??
|
|
false;
|
|
if (!isNetWork) {
|
|
return;
|
|
}
|
|
|
|
ShowTipView().showIosTipWithContentDialog(
|
|
'确定要删除吗?'.tr, () async {
|
|
state.isDeletAll = false;
|
|
state.deletKeyID = fingerprintItemData.remoteId.toString();
|
|
state.deletRemoteControlNo = int.parse(fingerprintItemData.remoteNumber!);
|
|
logic.senderAddRemoteControl();
|
|
});
|
|
},
|
|
backgroundColor: Colors.red,
|
|
foregroundColor: Colors.white,
|
|
label: '删除'.tr,
|
|
padding: EdgeInsets.only(left: 5.w, right: 5.w),
|
|
),
|
|
],
|
|
),
|
|
child: _keyItem(
|
|
'images/icon_remoteControl.png',
|
|
fingerprintItemData.remoteName!,
|
|
logic.getKeyType(fingerprintItemData),
|
|
logic.getKeyDateType(fingerprintItemData), () async {
|
|
await Get.toNamed(Routers.remoteControlDetailPage,
|
|
arguments: <String, FingerprintItemData>{
|
|
'fingerprintItemData': fingerprintItemData,
|
|
})!.then((data) {
|
|
getHttpData(isRefresh: true);
|
|
});
|
|
|
|
}),
|
|
);
|
|
},
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return const Divider(
|
|
height: 1,
|
|
color: AppColors.greyLineColor,
|
|
);
|
|
},
|
|
),
|
|
)
|
|
: NoData(
|
|
noDataHeight: 1.sh -
|
|
ScreenUtil().statusBarHeight -
|
|
ScreenUtil().bottomBarHeight -
|
|
190.h -
|
|
64.h));
|
|
}
|
|
|
|
Widget _keyItem(String lockTypeIcon, String lockTypeTitle,
|
|
String ifInvalidation, String showTime, Function() action) {
|
|
return GestureDetector(
|
|
onTap: action,
|
|
child: Container(
|
|
height: 90.h,
|
|
// margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w),
|
|
color: Colors.white,
|
|
child: Row(
|
|
children: <Widget>[
|
|
SizedBox(width: 30.w),
|
|
Container(
|
|
width: 60.w,
|
|
height: 60.w,
|
|
// padding: EdgeInsets.all(15.w),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(30.w),
|
|
color: AppColors.mainColor,
|
|
),
|
|
child: Image.asset(lockTypeIcon, width: 30.w, height: 30.w,)
|
|
),
|
|
SizedBox(width: 20.w),
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Row(
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
SizedBox(
|
|
width: 1.sw - 110.w - 100.w,
|
|
child: Row(
|
|
children: <Widget>[
|
|
Flexible(
|
|
child: Text(lockTypeTitle,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 24.sp,
|
|
color: AppColors.blackColor)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Text(ifInvalidation,
|
|
style: TextStyle(fontSize: 22.sp, color: Colors.red)),
|
|
SizedBox(width: 10.w),
|
|
],
|
|
),
|
|
SizedBox(height: 5.h),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: <Widget>[
|
|
Flexible(
|
|
child: Text(showTime,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 18.sp,
|
|
color: AppColors.placeholderTextColor)),
|
|
),
|
|
],
|
|
),
|
|
SizedBox(width: 20.h),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(width: 20.h),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@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;
|
|
}
|
|
|
|
/// 从下级返回 当前界面即将出现
|
|
@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;
|
|
}
|
|
}
|