221 lines
6.9 KiB
Dart
Executable File
221 lines
6.9 KiB
Dart
Executable File
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/mine/mineSet/transferSmartLock/transferSmartLockList/transferSmartLock_state.dart';
|
|
|
|
import '../../../../../appRouters.dart';
|
|
import '../../../../../app_settings/app_colors.dart';
|
|
import '../../../../../tools/titleAppBar.dart';
|
|
import '../../../../tools/EasyRefreshTool.dart';
|
|
import '../../../../tools/appRouteObserver.dart';
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
import '../../../../tools/keySearchWidget.dart';
|
|
import '../../../../tools/noData.dart';
|
|
import 'transferSmartLock_entity.dart';
|
|
import 'transferSmartLock_logic.dart';
|
|
|
|
class TransferSmartLockPage extends StatefulWidget {
|
|
const TransferSmartLockPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<TransferSmartLockPage> createState() => _TransferSmartLockPageState();
|
|
}
|
|
|
|
class _TransferSmartLockPageState extends State<TransferSmartLockPage> with RouteAware {
|
|
final TransferSmartLockLogic logic = Get.put(TransferSmartLockLogic());
|
|
final TransferSmartLockState state = Get.find<TransferSmartLockLogic>().state;
|
|
|
|
Future<void> getHttpData() async {
|
|
logic.getTransferLockListData().then((TransferSmartLockEntity value){
|
|
setState(() {});
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
getHttpData();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.mainBackgroundColor,
|
|
appBar: TitleAppBar(
|
|
barTitle: '选择锁'.tr,
|
|
haveBack: true,
|
|
backgroundColor: AppColors.mainColor,
|
|
actionsList: <Widget>[
|
|
TextButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
if(state.isSelectAll == true){
|
|
for (final TransferSmartLockItemData element in state.transferSmartLockListData.value) {
|
|
state.isSelectAll = false;
|
|
element.select = 0;
|
|
}
|
|
}else{
|
|
for (final TransferSmartLockItemData element in state.transferSmartLockListData.value) {
|
|
state.isSelectAll = true;
|
|
element.select = 1;
|
|
}
|
|
}
|
|
});
|
|
},
|
|
child: Text(state.isSelectAll == true ? '取消'.tr : '全选'.tr, style: TextStyle(color: Colors.white, fontSize: 24.sp)))
|
|
],
|
|
),
|
|
body: EasyRefreshTool(
|
|
onRefresh: (){
|
|
getHttpData();
|
|
},
|
|
child: Column(
|
|
children: <Widget>[
|
|
KeySearchWidget(
|
|
editingController: state.searchController,
|
|
onSubmittedAction: () {
|
|
getHttpData();
|
|
},
|
|
),
|
|
SizedBox(height: 10.h),
|
|
Expanded(child: _buildMainUI()),
|
|
SizedBox(height: 20.h),
|
|
_buildNextBtn(),
|
|
SizedBox(height: 64.h)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMainUI() {
|
|
return Obx(() => state.transferSmartLockListData.value.isNotEmpty ? ListView.separated(
|
|
itemCount: state.transferSmartLockListData.value.length,
|
|
separatorBuilder: (BuildContext context, int index) {
|
|
return Divider(
|
|
height: 1,
|
|
indent: 20.w,
|
|
endIndent: 20.w,
|
|
color: AppColors.greyLineColor,
|
|
);
|
|
},
|
|
itemBuilder: (BuildContext c, int index) {
|
|
final TransferSmartLockItemData transferSmartLockItemData = state.transferSmartLockListData.value[index];
|
|
return _electronicKeyItem(transferSmartLockItemData, () {
|
|
setState(() {
|
|
if(transferSmartLockItemData.select == 1){
|
|
transferSmartLockItemData.select = 0;
|
|
}else{
|
|
transferSmartLockItemData.select = 1;
|
|
}
|
|
});
|
|
});
|
|
}): NoData());
|
|
}
|
|
|
|
Widget _electronicKeyItem(TransferSmartLockItemData transferSmartLockItemData, Function() action) {
|
|
return GestureDetector(
|
|
onTap: action,
|
|
child: Container(
|
|
color: Colors.white,
|
|
// height: 90.h,
|
|
padding: EdgeInsets.only(top: 10.h, bottom: 10.h),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: <Widget>[
|
|
SizedBox(width: 20.w),
|
|
Image.asset((transferSmartLockItemData.select == 1) ? 'images/icon_round_select.png' : 'images/icon_round_unSelect.png', width: 30.w, height: 30.w),
|
|
SizedBox(width: 16.w),
|
|
Image.asset('images/icon_lockGroup_item.png', width: 50.h, height: 50.h, fit: BoxFit.fill),
|
|
SizedBox(width: 10.w),
|
|
Flexible(
|
|
child: Text(transferSmartLockItemData.lockAlias!, style: TextStyle(fontSize: 22.sp, color: AppColors.blackColor)),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildNextBtn() {
|
|
return GestureDetector(
|
|
child: Container(
|
|
color: AppColors.mainColor,
|
|
width: ScreenUtil().screenWidth,
|
|
height: 64.h,
|
|
child: TextButton(
|
|
onPressed: () async {
|
|
bool isCanNext = false;
|
|
final List idList = [];
|
|
for (final TransferSmartLockItemData element in state.transferSmartLockListData.value) {
|
|
if(element.select == 1){
|
|
isCanNext = true;
|
|
idList.add(element.lockId);
|
|
}
|
|
}
|
|
if(isCanNext == false){
|
|
logic.showToast('请选择锁'.tr);
|
|
return;
|
|
}
|
|
final data = await Get.toNamed(Routers.recipientInformationPage, arguments: <String, Object>{
|
|
'idList':idList,
|
|
'isFromType':1,
|
|
});
|
|
if(data != null) {
|
|
await getHttpData();
|
|
// eventBus.fire(RefreshLockListInfoDataEvent());
|
|
}
|
|
},
|
|
child: Text('下一步'.tr, style: TextStyle(fontSize: 28.sp, color: Colors.white),
|
|
)),
|
|
),
|
|
);
|
|
}
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
/// 返回上一个界面 当前界面即将消失
|
|
@override
|
|
void didPop() {
|
|
super.didPop();
|
|
eventBus.fire(RefreshLockListInfoDataEvent());
|
|
}
|
|
|
|
/// 从下级返回 当前界面即将出现
|
|
@override
|
|
void didPopNext() {
|
|
super.didPopNext();
|
|
|
|
}
|
|
|
|
/// 进入下级界面 当前界面即将消失
|
|
@override
|
|
void didPushNext() {
|
|
super.didPushNext();
|
|
|
|
}
|
|
}
|