160 lines
5.4 KiB
Dart
160 lines
5.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/src/widgets/framework.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:starcloud/entity/star_cloud_lock_list.dart';
|
|
import 'package:starwork_flutter/base/app_logger.dart';
|
|
import 'package:starwork_flutter/common/constant/app_colors.dart';
|
|
import 'package:starwork_flutter/common/constant/app_images.dart';
|
|
import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart';
|
|
import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart';
|
|
import 'package:starwork_flutter/extension/function_extension.dart';
|
|
import 'package:starwork_flutter/views/device/removeDevice/remove_device_controller.dart';
|
|
|
|
class RemoveDeviceView extends GetView<RemoveDeviceController> {
|
|
const RemoveDeviceView({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.scaffoldBackgroundColor,
|
|
appBar: CustomAppBarWidget(
|
|
title: '选择设备'.tr,
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
var allSelected = controller.isAllSelected(controller.deviceList);
|
|
if (allSelected) {
|
|
controller.clearSelection();
|
|
} else {
|
|
controller.selectAll(controller.deviceList);
|
|
}
|
|
},
|
|
child: Text(
|
|
'全选'.tr,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black87,
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
body: SafeArea(
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 10.w,
|
|
vertical: 10.h,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildDeviceList(),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
onPressed: () {
|
|
if (controller.selectedDevices.isEmpty) {
|
|
controller.showToast('请至少选中一个设备');
|
|
}
|
|
controller.removeDevice(controller.selectedDevices);
|
|
}.debounce(),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
padding: EdgeInsets.symmetric(vertical: 12.h),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
|
|
),
|
|
child: Text(
|
|
'删除'.tr,
|
|
style: TextStyle(
|
|
fontSize: 16.sp,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
_buildDeviceList() {
|
|
return Expanded(
|
|
child: ListView.builder(
|
|
itemCount: controller.deviceList.length,
|
|
itemBuilder: (context, index) {
|
|
final device = controller.deviceList[index];
|
|
return GestureDetector(
|
|
onTap: () {
|
|
controller.toggleDevice(device);
|
|
},
|
|
child: Container(
|
|
margin: EdgeInsets.only(bottom: 10.h),
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 10.w,
|
|
vertical: 4.h,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(8.r),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Obx(
|
|
() => Checkbox(
|
|
value: controller.isSelected(device), // 动态判断是否选中
|
|
shape: CircleBorder(
|
|
side: BorderSide(width: 0.4.w),
|
|
),
|
|
activeColor: Colors.blue,
|
|
onChanged: (value) {
|
|
controller.toggleDevice(device); // 切换状态
|
|
},
|
|
),
|
|
),
|
|
Image(
|
|
image: const AssetImage(AppImages.iconLockTypeDoorLock),
|
|
width: 26.w,
|
|
height: 26.w,
|
|
fit: BoxFit.contain,
|
|
gaplessPlayback: true,
|
|
// 防止闪烁
|
|
filterQuality: FilterQuality.medium,
|
|
// 优化过滤质量
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return Icon(
|
|
Icons.image_not_supported,
|
|
size: 26.sp,
|
|
color: Colors.grey,
|
|
);
|
|
},
|
|
),
|
|
SizedBox(
|
|
width: 8.w,
|
|
),
|
|
Expanded(
|
|
child: Text(
|
|
device.lockName,
|
|
style: TextStyle(
|
|
fontSize: 14.sp,
|
|
fontWeight: FontWeight.w500,
|
|
color: Colors.black87,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|