From 3cc225c762cb686f1089b77699d861c5616e1f98 Mon Sep 17 00:00:00 2001 From: liyi Date: Tue, 16 Sep 2025 18:06:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B5=E3=80=81=E8=AE=BE=E5=A4=87=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E4=BF=A1=E6=81=AF=E9=A1=B5=E3=80=81=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=A1=B9=E3=80=81=E8=AE=BE=E5=A4=87=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B9=E3=80=81=E6=90=9C=E7=B4=A2wifi=E3=80=81?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5wifi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/base_controller.dart | 3 + lib/common/constant/lock_function_number.dart | 3 + .../widgets/custom_cell_list_widget.dart | 34 +-- lib/common/widgets/custom_cell_widget.dart | 7 +- lib/routes/app_pages.dart | 14 ++ lib/routes/app_routes.dart | 2 + .../device_basis_info_binding.dart | 10 + .../device_basis_info_controller.dart | 42 ++++ .../device_basis_info_view.dart | 154 +++++++++++++ .../device_configure_network_controller.dart | 24 +- .../device_configure_network_view.dart | 206 +++++++++++++----- .../device_manage_controller.dart | 43 +++- .../deviceManage/device_manage_view.dart | 16 +- .../deviceSetting/device_setting_binding.dart | 9 + .../device_setting_controller.dart | 102 +++++++++ .../deviceSetting/device_setting_view.dart | 182 ++++++++++++++++ 16 files changed, 766 insertions(+), 85 deletions(-) create mode 100644 lib/common/constant/lock_function_number.dart create mode 100644 lib/views/device/deviceBasisInfo/device_basis_info_binding.dart create mode 100644 lib/views/device/deviceBasisInfo/device_basis_info_controller.dart create mode 100644 lib/views/device/deviceBasisInfo/device_basis_info_view.dart create mode 100644 lib/views/device/deviceSetting/device_setting_binding.dart create mode 100644 lib/views/device/deviceSetting/device_setting_controller.dart create mode 100644 lib/views/device/deviceSetting/device_setting_view.dart diff --git a/lib/base/base_controller.dart b/lib/base/base_controller.dart index de67215..a8df501 100644 --- a/lib/base/base_controller.dart +++ b/lib/base/base_controller.dart @@ -15,6 +15,9 @@ class BaseController extends GetxController { } void showLoading() { + if (EasyLoading.isShow) { + return; + } EasyLoading.show(status: AppToastMessages.loading); } diff --git a/lib/common/constant/lock_function_number.dart b/lib/common/constant/lock_function_number.dart new file mode 100644 index 0000000..f153a8d --- /dev/null +++ b/lib/common/constant/lock_function_number.dart @@ -0,0 +1,3 @@ +class LockFunctionNumber { + static const int remoteUnlocking = 28; +} diff --git a/lib/common/widgets/custom_cell_list_widget.dart b/lib/common/widgets/custom_cell_list_widget.dart index 8a7ac7e..0a12a0d 100644 --- a/lib/common/widgets/custom_cell_list_widget.dart +++ b/lib/common/widgets/custom_cell_list_widget.dart @@ -13,27 +13,33 @@ class CustomCellListWidget extends StatelessWidget { @override Widget build(BuildContext context) { + // ✅ 第一步:过滤出 visible == true 的项 + final visibleChildren = children + .where((child) => (child.visible ?? true)) // 假设 CustomCellWidget 有 visible 属性 + .toList(); + + // ✅ 第二步:只在可见项之间添加 Divider + final List items = []; + for (int i = 0; i < visibleChildren.length; i++) { + items.add(visibleChildren[i]); + if (i < visibleChildren.length - 1) { + items.add(Divider( + height: 0.5.h, + thickness: 0.5.h, + color: Colors.grey[300], + )); + } + } + return Container( width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(8.r)), ), - padding: EdgeInsets.symmetric( - horizontal: 10.w, - ), + padding: EdgeInsets.symmetric(horizontal: 10.w), child: Column( - children: [ - for (int i = 0; i < children.length; i++) ...[ - children[i], - if (i < children.length - 1) - Divider( - height: 0.5.h, - thickness: 0.5.h, - color: Colors.grey[300], - ), - ], - ], + children: items, // ✅ 只渲染可见项和它们之间的分隔线 ), ); } diff --git a/lib/common/widgets/custom_cell_widget.dart b/lib/common/widgets/custom_cell_widget.dart index 9a1111e..d829896 100644 --- a/lib/common/widgets/custom_cell_widget.dart +++ b/lib/common/widgets/custom_cell_widget.dart @@ -9,15 +9,20 @@ class CustomCellWidget extends StatelessWidget { this.leftIcon, this.rightWidget, this.onTap, + this.visible = true, }); final String leftText; final Icon? leftIcon; final Widget? rightWidget; final GestureTapCallback? onTap; - + final bool visible; // 控制是否显示 @override Widget build(BuildContext context) { + // 如果不显示,返回空 + if (!visible) { + return const SizedBox.shrink(); + } return GestureDetector( onTap: onTap, child: Container( diff --git a/lib/routes/app_pages.dart b/lib/routes/app_pages.dart index b4d1974..3f572c2 100644 --- a/lib/routes/app_pages.dart +++ b/lib/routes/app_pages.dart @@ -2,12 +2,16 @@ import 'package:get/get.dart'; import 'package:starwork_flutter/routes/app_routes.dart'; import 'package:starwork_flutter/views/device/confirmPairDevice/confirm_pair_device_binding.dart'; import 'package:starwork_flutter/views/device/confirmPairDevice/confirm_pair_device_view.dart'; +import 'package:starwork_flutter/views/device/deviceBasisInfo/device_basis_info_binding.dart'; +import 'package:starwork_flutter/views/device/deviceBasisInfo/device_basis_info_view.dart'; import 'package:starwork_flutter/views/device/deviceConfigureNetwork/device_configure_network_binding.dart'; import 'package:starwork_flutter/views/device/deviceConfigureNetwork/device_configure_network_view.dart'; import 'package:starwork_flutter/views/device/deviceManage/device_manage_binding.dart'; import 'package:starwork_flutter/views/device/deviceManage/device_manage_view.dart'; import 'package:starwork_flutter/views/device/deviceSearchNetwork/device_search_network_binding.dart'; import 'package:starwork_flutter/views/device/deviceSearchNetwork/device_search_network_view.dart'; +import 'package:starwork_flutter/views/device/deviceSetting/device_setting_binding.dart'; +import 'package:starwork_flutter/views/device/deviceSetting/device_setting_view.dart'; import 'package:starwork_flutter/views/device/removeDevice/remove_device_binding.dart'; import 'package:starwork_flutter/views/device/removeDevice/remove_device_view.dart'; import 'package:starwork_flutter/views/device/searchDevice/search_device_binding.dart'; @@ -151,5 +155,15 @@ class AppPages { page: () => DeviceSearchNetworkView(), binding: DeviceSearchNetworkBinding(), ), + GetPage( + name: AppRoutes.deviceSetting, + page: () => DeviceSettingView(), + binding: DeviceSettingBinding(), + ), + GetPage( + name: AppRoutes.deviceBasisInfo, + page: () => DeviceBasisInfoView(), + binding: DeviceBasisInfoBinding(), + ), ]; } diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index ff6793a..84ed543 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -21,4 +21,6 @@ class AppRoutes{ static const String deviceRemoveDevice = '/device/removeDevice'; static const String deviceSearchNetwork = '/device/searchNetwork'; static const String deviceConfigureNetwork = '/device/configureNetwork'; + static const String deviceSetting = '/device/deviceSetting'; + static const String deviceBasisInfo = '/device/deviceBasisInfo'; } \ No newline at end of file diff --git a/lib/views/device/deviceBasisInfo/device_basis_info_binding.dart b/lib/views/device/deviceBasisInfo/device_basis_info_binding.dart new file mode 100644 index 0000000..8b714e9 --- /dev/null +++ b/lib/views/device/deviceBasisInfo/device_basis_info_binding.dart @@ -0,0 +1,10 @@ +import 'package:get/get.dart'; +import 'package:starwork_flutter/views/device/deviceBasisInfo/device_basis_info_controller.dart'; +import 'package:starwork_flutter/views/device/deviceSetting/device_setting_controller.dart'; + +class DeviceBasisInfoBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut(() => DeviceBasisInfoController()); + } +} diff --git a/lib/views/device/deviceBasisInfo/device_basis_info_controller.dart b/lib/views/device/deviceBasisInfo/device_basis_info_controller.dart new file mode 100644 index 0000000..62135bb --- /dev/null +++ b/lib/views/device/deviceBasisInfo/device_basis_info_controller.dart @@ -0,0 +1,42 @@ +import 'package:get/get.dart'; +import 'package:starcloud/entity/star_cloud_lock_list.dart'; +import 'package:starcloud/sdk/sdk_device_operate_extension.dart'; +import 'package:starcloud/sdk/starcloud.dart'; +import 'package:starwork_flutter/base/app_logger.dart'; +import 'package:starwork_flutter/base/base_controller.dart'; +import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart'; + +class DeviceBasisInfoController extends BaseController { + // 页面传递过来的锁信息 + StarCloudLock? lockInfo; + + // 锁详情信息 + final lockDetailsInfo = StarCloudLock.empty().obs; + + @override + void onReady() { + super.onReady(); + // 读取参数 + final args = Get.arguments; + if (args != null && args.containsKey(AppViewParameterKeys.lockInfo)) { + final json = args[AppViewParameterKeys.lockInfo]; + lockInfo = StarCloudLock.fromJson(json, 0); + } + + _requestDetailsInfo(); + } + + void _requestDetailsInfo() async { + await StarCloudSDK.instance.getDevice( + lockId: lockInfo?.lockId ?? 0, + onSuccess: (lockInfo) { + + lockDetailsInfo.value = lockInfo; + AppLogger.highlight('message:${lockInfo}'); + }, + onError: (error) { + AppLogger.error('message:${error}'); + }, + ); + } +} diff --git a/lib/views/device/deviceBasisInfo/device_basis_info_view.dart b/lib/views/device/deviceBasisInfo/device_basis_info_view.dart new file mode 100644 index 0000000..091ce25 --- /dev/null +++ b/lib/views/device/deviceBasisInfo/device_basis_info_view.dart @@ -0,0 +1,154 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:starwork_flutter/common/constant/app_colors.dart'; +import 'package:starwork_flutter/common/constant/app_images.dart'; +import 'package:starwork_flutter/common/widgets/custom_cell_list_widget.dart'; +import 'package:starwork_flutter/common/widgets/custom_cell_widget.dart'; +import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart'; +import 'package:starwork_flutter/views/device/deviceBasisInfo/device_basis_info_controller.dart'; +import 'package:starwork_flutter/views/device/deviceSetting/device_setting_controller.dart'; + +class DeviceBasisInfoView extends GetView { + @override + Widget build(BuildContext context) { + // 即使不使用,只是引用一下 controller 就能触发初始化 + final _ = controller; // 添加这一行 + + return Scaffold( + backgroundColor: AppColors.scaffoldBackgroundColor, + appBar: CustomAppBarWidget( + title: '基本信息'.tr, + ), + body: SafeArea( + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 10.w, + vertical: 10.h, + ), + child: Column( + children: [ + Obx( + () => CustomCellListWidget( + children: [ + CustomCellWidget( + leftText: '设备图片'.tr, + onTap: () {}, + rightWidget: Image( + image: AssetImage(AppImages.iconLockTypeDoorLock), + width: 48.w, + height: 48.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, + ); + }, + ), + ), + CustomCellWidget( + leftText: '型号'.tr, + onTap: () { + // 复制到剪切板 + Clipboard.setData(ClipboardData(text: '1231231231')); + controller.showToast('内容已复制'.tr); + }, + rightWidget: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + controller.lockDetailsInfo.value.model, + style: TextStyle( + fontSize: 14.sp, + color: Colors.black54, + fontWeight: FontWeight.w400, + ), + ), + SizedBox( + width: 4.w, + ), + Icon( + Icons.library_books_rounded, + size: 16.sp, + color: Colors.grey, + ) + ], + ), + ), + CustomCellWidget( + leftText: '名称'.tr, + onTap: () { + // 复制到剪切板 + Clipboard.setData(ClipboardData(text: '1231231231')); + controller.showToast('内容已复制'.tr); + }, + rightWidget: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + controller.lockDetailsInfo.value.lockName, + style: TextStyle( + fontSize: 14.sp, + color: Colors.black54, + fontWeight: FontWeight.w400, + ), + ), + SizedBox( + width: 4.w, + ), + Icon( + Icons.library_books_rounded, + size: 16.sp, + color: Colors.grey, + ) + ], + ), + ), + CustomCellWidget( + leftText: '当前固件版本'.tr, + onTap: () { + // 复制到剪切板 + Clipboard.setData(ClipboardData(text: '1231231231')); + controller.showToast('内容已复制'.tr); + }, + rightWidget: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + controller.lockDetailsInfo.value.fwVersion, + style: TextStyle( + fontSize: 14.sp, + color: Colors.black54, + fontWeight: FontWeight.w400, + ), + ), + SizedBox( + width: 4.w, + ), + Icon( + Icons.library_books_rounded, + size: 16.sp, + color: Colors.grey, + ) + ], + ), + ), + ], + ), + ) + ], + ), + ), + ), + ); + } +} diff --git a/lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart b/lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart index 380b5c4..7f4e200 100644 --- a/lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart +++ b/lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart @@ -6,6 +6,8 @@ import 'package:starcloud/sdk/sdk_configure_network_operate_extension.dart'; import 'package:starcloud/sdk/starcloud.dart'; import 'package:starwork_flutter/base/base_controller.dart'; import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart'; +import 'package:starwork_flutter/flavors.dart'; +import 'package:starwork_flutter/routes/app_routes.dart'; class DeviceConfigureNetworkController extends BaseController { // 锁信息 @@ -13,6 +15,7 @@ class DeviceConfigureNetworkController extends BaseController { StarCloudSearchWifiResult? networkInfo; TextEditingController wifiNameInputController = TextEditingController(); + TextEditingController wifiPasswordInputController = TextEditingController(); @override void onReady() { @@ -27,19 +30,30 @@ class DeviceConfigureNetworkController extends BaseController { final json = args[AppViewParameterKeys.networkInfo]; networkInfo = StarCloudSearchWifiResult.fromJson(json); } + + wifiNameInputController.text = networkInfo?.ssid ?? ''; } void configureNetwork() { + if (wifiNameInputController.text.isEmpty) { + showToast('WIFI昵称不能为空'); + return; + } + showLoading(); StarCloudSDK.instance.connectWiFi( lockId: lockInfo!.lockId, onError: (err) { print("配置网络失败:${err}"); + showError(message: '配网失败,请重试'.tr); }, - onSuccess: () {}, - wifiName: networkInfo!.ssid, - wifiPassword: '', - clientId: '', - starLockPeerId: '', + onSuccess: () { + showSuccess(message: '配网成功'.tr); + Get.back(); + }, + wifiName: wifiNameInputController.text, + wifiPassword: wifiPasswordInputController.text, + clientId: F.starCloudClientId, + starLockPeerId: '1232235156156', ); } } diff --git a/lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart b/lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart index 4cbe100..22a0ab2 100644 --- a/lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart +++ b/lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart @@ -4,6 +4,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:starwork_flutter/common/constant/app_colors.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/deviceConfigureNetwork/device_configure_network_controller.dart'; class DeviceConfigureNetworkView extends GetView { @@ -18,61 +19,166 @@ class DeviceConfigureNetworkView extends GetView().listen((event) async { _requestTeamDeviceList(); }); + + // 监听搜索输入框变化 + searchInputController.addListener(() { + _updateFilteredList(); // 输入变化时重新过滤 + }); } @override void onClose() { super.onClose(); _refreshDeviceListSubscription.cancel(); + searchInputController.dispose(); } void initData() async { @@ -65,23 +74,33 @@ class DeviceManageController extends BaseController with GetSingleTickerProvider } /// 根据当前 selectedStatusIndex 过滤设备列表 + /// 根据当前 selectedStatusIndex 和 搜索关键词 过滤设备列表 void _updateFilteredList() { - List filtered = []; + List filtered = deviceList; + // Step 1: 先按状态筛选 switch (selectedStatusIndex.value) { case 0: // 全部 - filtered = deviceList; break; case 1: // 在线 - filtered = deviceList.where((device) => device.isOnline == true).toList(); + filtered = filtered.where((device) => device.network?.isOnline == 1).toList(); break; case 2: // 离线 - filtered = deviceList.where((device) => device.isOnline == false).toList(); + filtered = filtered.where((device) => device.network?.isOnline == 0).toList(); break; - default: - filtered = deviceList; } - filteredDeviceList.assignAll(filtered); // 更新响应式列表 + + // Step 2: 再按搜索关键词过滤(设备名称) + final String keyword = searchInputController.text.trim(); + if (keyword.isNotEmpty) { + filtered = filtered.where((device) { + final name = device.lockName ?? ''; + return name.toLowerCase().contains(keyword.toLowerCase()); + }).toList(); + } + + // 更新 UI 列表 + filteredDeviceList.assignAll(filtered); } void _requestTeamDeviceList() async { @@ -96,13 +115,21 @@ class DeviceManageController extends BaseController with GetSingleTickerProvider for (var groupItem in list.groupList) { for (var lock in groupItem.lockList) { deviceList.add(lock); - if (lock.isOnline ?? false) { + if (lock.network?.isOnline == 1) { onlineDeviceCount.value++; } else { offlineDeviceCount.value++; } } } + // ✅ 在更新过滤前,先对 deviceList 按在线状态排序:在线在前,离线在后 + deviceList.sort((a, b) { + final aOnline = a.network?.isOnline == 1; + final bOnline = b.network?.isOnline == 1; + if (aOnline == bOnline) return 0; // 状态相同,顺序不变 + if (aOnline) return -1; // a 在线,排前面 + return 1; // b 在线,或都离线,a 排后面 + }); // ✅ 加载完原始数据后,更新过滤列表 _updateFilteredList(); hideLoading(); diff --git a/lib/views/device/deviceManage/device_manage_view.dart b/lib/views/device/deviceManage/device_manage_view.dart index cd90a99..7d4a5f9 100644 --- a/lib/views/device/deviceManage/device_manage_view.dart +++ b/lib/views/device/deviceManage/device_manage_view.dart @@ -114,8 +114,10 @@ class DeviceManageView extends GetView { _buildSearchBar() { return TextField( + controller: controller.searchInputController, + textInputAction: TextInputAction.search, decoration: InputDecoration( - hintText: '请输入设备名称或编号'.tr, + hintText: '请输入设备名称'.tr, hintStyle: TextStyle( fontSize: 14.sp, color: const Color(0xFF999999), @@ -290,8 +292,8 @@ class DeviceManageView extends GetView { final lock = controller.filteredDeviceList[index]; return GestureDetector( onTap: () { - Get.toNamed(AppRoutes.deviceSearchNetwork, arguments: { - 'lockInfo': lock.toJson(), + Get.toNamed(AppRoutes.deviceSetting, arguments: { + AppViewParameterKeys.lockInfo: lock.toJson(), }); }, child: Container( @@ -333,8 +335,8 @@ class DeviceManageView extends GetView { Text( lock.lockName, style: TextStyle( - fontSize: 10.sp, - fontWeight: FontWeight.w400, + fontSize: 11.sp, + fontWeight: FontWeight.w500, ), maxLines: 1, overflow: TextOverflow.ellipsis, @@ -343,9 +345,9 @@ class DeviceManageView extends GetView { height: 4.h, ), Text( - lock.isOnline ?? false ? '在线' : '离线', + lock.network?.isOnline == 1 ? '在线' : '离线', style: TextStyle( - color: lock.isOnline ?? false ? Colors.green : Colors.grey, + color: lock.network?.isOnline == 1 ? Colors.green : Colors.grey, fontSize: 10.sp, fontWeight: FontWeight.w500, ), diff --git a/lib/views/device/deviceSetting/device_setting_binding.dart b/lib/views/device/deviceSetting/device_setting_binding.dart new file mode 100644 index 0000000..2a069b3 --- /dev/null +++ b/lib/views/device/deviceSetting/device_setting_binding.dart @@ -0,0 +1,9 @@ +import 'package:get/get.dart'; +import 'package:starwork_flutter/views/device/deviceSetting/device_setting_controller.dart'; + +class DeviceSettingBinding extends Bindings { + @override + void dependencies() { + Get.lazyPut(() => DeviceSettingController()); + } +} diff --git a/lib/views/device/deviceSetting/device_setting_controller.dart b/lib/views/device/deviceSetting/device_setting_controller.dart new file mode 100644 index 0000000..9250ba3 --- /dev/null +++ b/lib/views/device/deviceSetting/device_setting_controller.dart @@ -0,0 +1,102 @@ +import 'package:get/get.dart'; +import 'package:get/get_rx/get_rx.dart'; +import 'package:starcloud/entity/star_cloud_lock_list.dart'; +import 'package:starcloud/net/entity/api_response.dart'; +import 'package:starcloud/sdk/entity/entity_sender/enable_lock_settings.dart'; + +import 'package:starcloud/sdk/sdk_lock_setting_operate_extension.dart'; +import 'package:starcloud/sdk/starcloud.dart'; +import 'package:starwork_flutter/base/app_logger.dart'; +import 'package:starwork_flutter/base/base_controller.dart'; +import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart'; +import 'package:starwork_flutter/common/constant/lock_function_number.dart'; +import 'package:starwork_flutter/common/events/refresh_device_list_event.dart'; +import 'package:starwork_flutter/common/utils/event_bus_util.dart'; + +class DeviceSettingController extends BaseController { + // 锁信息 + StarCloudLock? lockInfo; + + // 锁名称 + RxString lockName = ''.obs; + + // 定义一个可观察的 Map + final lockFeatureMap = {}.obs; + final lockSettingMap = {}.obs; + + @override + void onReady() { + super.onReady(); + // 读取参数 + final args = Get.arguments; + if (args != null && args.containsKey(AppViewParameterKeys.lockInfo)) { + final json = args[AppViewParameterKeys.lockInfo]; + lockInfo = StarCloudLock.fromJson(json, 0); + lockName.value = lockInfo?.lockName ?? ''; + } + + _readLockSetting(); + _readLockFeature(); + } + + // 开启/关闭远程开锁 + void enableRemoteUnlock(bool value) async { + showLoading(); + await StarCloudSDK.instance.enableLockSettings( + lockId: lockInfo?.lockId ?? 0, + lockSettings: EnableLockSettings( + featureBit: LockFunctionNumber.remoteUnlocking, + featureEnable: value, + parameter: null, + ), + onSuccess: () { + _readLockSetting(); + hideLoading(); + }, + onError: (err) { + AppLogger.error('开启/关闭远程开锁失败:${err}'); + hideLoading(); + }, + ); + } + + void _readLockSetting() async { + showLoading(); + await StarCloudSDK.instance.readLockSetting( + lockId: lockInfo?.lockId ?? 0, + onSuccess: (response) { + if (response is ApiResponse) { + final resultData = response as ApiResponse; + if (resultData.isSuccess) { + lockSettingMap.value = resultData.data['lockSetting']; + } + } + hideLoading(); + }, + onError: (err) { + AppLogger.error('读取锁设置失败:${err}'); + hideLoading(); + }, + ); + } + + void _readLockFeature() async { + showLoading(); + await StarCloudSDK.instance.readLockFeature( + lockId: lockInfo?.lockId ?? 0, + onSuccess: (response) { + if (response is ApiResponse) { + final resultData = response as ApiResponse; + if (resultData.isSuccess) { + lockFeatureMap.value = resultData.data['lockFeature']; + } + } + hideLoading(); + }, + onError: (err) { + AppLogger.error('读取锁设置失败:${err}'); + hideLoading(); + }, + ); + } +} diff --git a/lib/views/device/deviceSetting/device_setting_view.dart b/lib/views/device/deviceSetting/device_setting_view.dart new file mode 100644 index 0000000..c8ab237 --- /dev/null +++ b/lib/views/device/deviceSetting/device_setting_view.dart @@ -0,0 +1,182 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/widgets.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.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/custom_cell_list_widget.dart'; +import 'package:starwork_flutter/common/widgets/custom_cell_widget.dart'; +import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart'; +import 'package:starwork_flutter/extension/function_extension.dart'; +import 'package:starwork_flutter/routes/app_routes.dart'; +import 'package:starwork_flutter/views/device/deviceSetting/device_setting_controller.dart'; + +class DeviceSettingView extends GetView { + @override + Widget build(BuildContext context) { + // 即使不使用,只是引用一下 controller 就能触发初始化 + final _ = controller; // 添加这一行 + + return Scaffold( + appBar: CustomAppBarWidget( + title: '设置'.tr, + ), + backgroundColor: AppColors.scaffoldBackgroundColor, + body: SafeArea( + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 10.w, + vertical: 10.h, + ), + child: Column( + children: [ + GestureDetector( + onTap: () { + Get.toNamed(AppRoutes.deviceBasisInfo, arguments: { + AppViewParameterKeys.lockInfo: controller.lockInfo?.toJson(), + }); + }, + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8.r), + ), + padding: EdgeInsets.symmetric( + horizontal: 10.w, + vertical: 10.h, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + children: [ + Image( + image: const AssetImage(AppImages.iconLockTypeDoorLock), + width: 38.w, + height: 38.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: 10.w, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Obx( + () => Text( + controller.lockName.value, + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.w400, + ), + ), + ), + SizedBox( + height: 4.h, + ), + Text( + '设备名称、序列号、版本等', + style: TextStyle(fontSize: 12.sp, fontWeight: FontWeight.w400, color: Colors.grey), + ) + ], + ), + ], + ), + Icon( + Icons.arrow_forward_ios_rounded, + size: 16.sp, + color: Colors.grey, + ) + ], + ), + ), + ), + SizedBox( + height: 10.h, + ), + Obx( + () => CustomCellListWidget( + children: [ + CustomCellWidget( + leftText: '远程开锁'.tr, + onTap: () {}, + visible: controller.lockFeatureMap['remoteUnlock'] == 1, + rightWidget: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + CupertinoSwitch( + value: controller.lockSettingMap['remoteUnlock'] == 1, + onChanged: (bool value) { + controller.enableRemoteUnlock(value); + }, + activeColor: Colors.blue, // 可选:打开时的颜色(iOS 默认为系统蓝色,可自定义) + trackColor: Colors.grey, // 可选:关闭时的背景轨道颜色 + ), + ], + ), + ), + CustomCellWidget( + leftText: '网络配置'.tr, + onTap: () { + Get.toNamed(AppRoutes.deviceSearchNetwork, arguments: { + AppViewParameterKeys.lockInfo: controller.lockInfo?.toJson(), + }); + }, + visible: controller.lockFeatureMap['wifi'] == 1, + rightWidget: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Icon( + Icons.arrow_forward_ios_rounded, + size: 16.sp, + color: Colors.grey, + ) + ], + ), + ), + ], + ), + ), + SizedBox( + height: 10.h, + ), + SizedBox( + width: double.infinity, + child: ElevatedButton( + onPressed: () {}.debounce(), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.red, + 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, + ), + ), + ), + ), + ], + ), + ), + ), + ); + } +}