From 406a9dd217443bf551c845b392907f66308eae97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Sat, 9 Mar 2024 17:17:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E9=94=81=E6=9D=BF=E8=8E=B7=E5=8F=96=E9=99=84=E8=BF=91wifi?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E9=85=8D=E7=BD=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/cn/starlock/lock/MainActivity.kt | 21 ++- star_lock/ios/Podfile.lock | 23 +-- .../xcshareddata/xcschemes/dev.xcscheme | 6 +- star_lock/lib/appRouters.dart | 9 +- star_lock/lib/blue/blue_manage.dart | 10 +- .../lib/blue/io_protocol/io_getWifiList.dart | 107 ++++++++++++ star_lock/lib/blue/reciver_data.dart | 7 + star_lock/lib/blue/sender_manage.dart | 22 +++ .../authorizedAdmin/authorizedAdmin_page.dart | 10 +- .../card/addCardType/addCardType_page.dart | 24 +++ .../sendElectronicKey_page.dart | 6 +- .../addFingerprintType_page.dart | 24 +++ .../lockDetail/lockDetail_logic.dart | 83 ++++++--- .../configuringWifiEntity.dart | 0 .../configuringWifi_logic.dart | 26 +-- .../configuringWifi_page.dart | 14 +- .../configuringWifi_state.dart | 7 +- .../wifiList/wifiList_logic.dart | 157 ++++++++++++++++++ .../wifiList/wifiList_page.dart | 127 ++++++++++++++ .../wifiList/wifiList_state.dart | 18 ++ .../lockSet/lockSet/lockSet_logic.dart | 47 +++--- .../lockSet/lockSet/lockSet_page.dart | 5 +- .../passwordKeyDetail_page.dart | 6 +- .../passwordKey_perpetual_page.dart | 6 +- .../main/lockMian/lockMain/lockMain_page.dart | 19 ++- .../addLock/nearbyLock/nearbyLock_logic.dart | 1 + .../messageList/messageList_logic.dart | 8 +- .../message/messageList/messageList_page.dart | 5 +- star_lock/lib/network/api_repository.dart | 2 +- .../lib/tools/NativeInteractionTool.dart | 34 +++- star_lock/lib/tools/baseGetXController.dart | 51 ++++++ star_lock/pubspec.yaml | 5 +- 32 files changed, 775 insertions(+), 115 deletions(-) create mode 100644 star_lock/lib/blue/io_protocol/io_getWifiList.dart rename star_lock/lib/main/lockDetail/lockSet/configuringWifi/{ => configuringWifi}/configuringWifiEntity.dart (100%) rename star_lock/lib/main/lockDetail/lockSet/configuringWifi/{ => configuringWifi}/configuringWifi_logic.dart (93%) rename star_lock/lib/main/lockDetail/lockSet/configuringWifi/{ => configuringWifi}/configuringWifi_page.dart (92%) rename star_lock/lib/main/lockDetail/lockSet/configuringWifi/{ => configuringWifi}/configuringWifi_state.dart (79%) create mode 100644 star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart create mode 100644 star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_page.dart create mode 100644 star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_state.dart diff --git a/star_lock/android/app/src/main/kotlin/cn/starlock/lock/MainActivity.kt b/star_lock/android/app/src/main/kotlin/cn/starlock/lock/MainActivity.kt index 9d1689e4..59482b41 100644 --- a/star_lock/android/app/src/main/kotlin/cn/starlock/lock/MainActivity.kt +++ b/star_lock/android/app/src/main/kotlin/cn/starlock/lock/MainActivity.kt @@ -10,7 +10,7 @@ import io.flutter.embedding.android.FlutterActivity import io.flutter.plugin.common.MethodChannel import io.flutter.embedding.engine.FlutterEngine; import io.flutter.plugins.GeneratedPluginRegistrant - +import android.bluetooth.BluetoothAdapter; class MainActivity: FlutterActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -22,6 +22,25 @@ class MainActivity: FlutterActivity() { if (call.method == "loadNativeShare") { var map = call.arguments as Map shareText(map["shareText"], "分享") + } else if (call.method == "sendGetBlueStatus") { + // 蓝牙是否开启 +// println("收到原生的信息了 methodmethodmethod: ${call.method}") + val bluetoothAdapter: BluetoothAdapter? = BluetoothAdapter.getDefaultAdapter() + var status = "0" + bluetoothAdapter?.let { + if (it.isEnabled) { + // 蓝牙已开启 + status = "1" + } else { + // 蓝牙已关闭 + status = "0" + } + } ?: run { + // 设备不支持蓝牙 + status = "-1" + } + val flutterEngine: FlutterEngine? = this.flutterEngine // 获取你的 FlutterEngine 实例 + MethodChannel(flutterEngine?.dartExecutor!!.binaryMessenger, "starLockFlutterReceive").invokeMethod("getBlueStatus", status) } else { result.notImplemented() // 没有实现的方法 } diff --git a/star_lock/ios/Podfile.lock b/star_lock/ios/Podfile.lock index ee862ec2..32bbc289 100644 --- a/star_lock/ios/Podfile.lock +++ b/star_lock/ios/Podfile.lock @@ -50,15 +50,12 @@ PODS: - Flutter - flutter_sound_core (= 9.2.13) - flutter_sound_core (9.2.13) - - flutter_voice_processor (1.1.0): + - flutter_voice_processor (1.1.1): - Flutter - ios-voice-processor (~> 1.1.0) - fluttertoast (0.0.2): - Flutter - Toast - - FMDB (2.7.5): - - FMDB/standard (= 2.7.5) - - FMDB/standard (2.7.5) - g711_flutter (0.0.1): - Flutter - google_maps_flutter_ios (0.0.1): @@ -96,8 +93,10 @@ PODS: - FlutterMacOS - sqflite (0.0.3): - Flutter - - FMDB (>= 2.7.5) + - FlutterMacOS - SwiftProtobuf (1.25.2) + - system_settings (0.0.1): + - Flutter - Toast (4.0.0) - url_launcher_ios (0.0.1): - Flutter @@ -135,7 +134,8 @@ DEPENDENCIES: - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - reactive_ble_mobile (from `.symlinks/plugins/reactive_ble_mobile/ios`) - shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`) - - sqflite (from `.symlinks/plugins/sqflite/ios`) + - sqflite (from `.symlinks/plugins/sqflite/darwin`) + - system_settings (from `.symlinks/plugins/system_settings/ios`) - url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`) - video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/ios`) - webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`) @@ -153,7 +153,6 @@ SPEC REPOS: - AMapFoundation - AMapLocation - flutter_sound_core - - FMDB - GoogleMaps - ios-voice-processor - Protobuf @@ -217,7 +216,9 @@ EXTERNAL SOURCES: shared_preferences_foundation: :path: ".symlinks/plugins/shared_preferences_foundation/darwin" sqflite: - :path: ".symlinks/plugins/sqflite/ios" + :path: ".symlinks/plugins/sqflite/darwin" + system_settings: + :path: ".symlinks/plugins/system_settings/ios" url_launcher_ios: :path: ".symlinks/plugins/url_launcher_ios/ios" video_player_avfoundation: @@ -250,9 +251,8 @@ SPEC CHECKSUMS: flutter_pcm_sound: de0572ca4f99091cc2abfcc31601b8a4ddd33c0e flutter_sound: c60effa2a350fb977885f0db2fbc4c1ad5160900 flutter_sound_core: 26c10e5832e76aaacfae252d8925232281c486ae - flutter_voice_processor: 53afbf59ad3feb82f4a379fea9ed8dc98495210f + flutter_voice_processor: 2b89b93d69b02227ae3fd58589ee0bcfa3ca2a82 fluttertoast: 31b00dabfa7fb7bacd9e7dbee580d7a2ff4bf265 - FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a g711_flutter: 8f2769052d2cf3549f83d11e1c42d81d94441123 google_maps_flutter_ios: d1318b4ff711612cab16862d7a87e31a7403d458 GoogleMaps: 20d7b12be49a14287f797e88e0e31bc4156aaeb4 @@ -268,8 +268,9 @@ SPEC CHECKSUMS: ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825 reactive_ble_mobile: 9ce6723d37ccf701dbffd202d487f23f5de03b4c shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695 - sqflite: 50a33e1d72bd59ee092a519a35d107502757ebed + sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1 + system_settings: 8f5cdbfa72c677fc8d665b863bcc20d393d87e9d Toast: 91b396c56ee72a5790816f40d3a94dd357abc196 url_launcher_ios: bbd758c6e7f9fd7b5b1d4cde34d2b95fcce5e812 video_player_avfoundation: 81e49bb3d9fb63dccf9fa0f6d877dc3ddbeac126 diff --git a/star_lock/ios/Runner.xcodeproj/xcshareddata/xcschemes/dev.xcscheme b/star_lock/ios/Runner.xcodeproj/xcshareddata/xcschemes/dev.xcscheme index d6d589e2..65ac7bdc 100644 --- a/star_lock/ios/Runner.xcodeproj/xcshareddata/xcschemes/dev.xcscheme +++ b/star_lock/ios/Runner.xcodeproj/xcshareddata/xcschemes/dev.xcscheme @@ -7,7 +7,7 @@ buildImplicitDependencies = "YES"> @@ -24,7 +24,7 @@ + buildConfiguration = "Release-dev"> const MessageDetailPage())), GetPage( name: Routers.accessoriesListPage, - page: (() => const AccessoriesListPage())) + page: (() => const AccessoriesListPage())), + GetPage( + name: Routers.wifiListPage, + page: (() => const WifiListPage())) ]; } diff --git a/star_lock/lib/blue/blue_manage.dart b/star_lock/lib/blue/blue_manage.dart index 0258d7d8..2c6aba86 100644 --- a/star_lock/lib/blue/blue_manage.dart +++ b/star_lock/lib/blue/blue_manage.dart @@ -40,7 +40,9 @@ class BlueManage { DeviceConnectionState? deviceConnectionState = DeviceConnectionState.disconnected; static BlueManage? _manager; - BlueManage._init(); + BlueManage._init(){ + // _initBlue(); + } static BlueManage? shareManager() { _manager ??= BlueManage._init(); @@ -111,6 +113,10 @@ class BlueManage { Future bludSendData(String deviceName, ConnectStateCallBack stateCallBack, {bool isAddEquipment = false}) async { _flutterReactiveBle!.statusStream.listen((status) { Get.log("_flutterReactiveBle.status:$status"); + if(deviceName.isEmpty) { + Get.log("deviceName为空"); + return; + } if (status == BleStatus.ready) { // 蓝牙已开启,可以进行蓝牙操作 if(deviceConnectionState != DeviceConnectionState.connected){ @@ -283,7 +289,7 @@ class BlueManage { // 写入 Future writeCharacteristicWithResponse(List value) async { QualifiedCharacteristic characteristic = QualifiedCharacteristic(characteristicId: _characteristicIdWrite, serviceId: _serviceIdWrite, deviceId: connectDeviceMacAddress); - int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 250); + int mtuLength = await _flutterReactiveBle!.requestMtu(deviceId: characteristic.deviceId, mtu: 512); print("mtuLength:$mtuLength"); try { List valueList = value; diff --git a/star_lock/lib/blue/io_protocol/io_getWifiList.dart b/star_lock/lib/blue/io_protocol/io_getWifiList.dart new file mode 100644 index 00000000..4d8d8528 --- /dev/null +++ b/star_lock/lib/blue/io_protocol/io_getWifiList.dart @@ -0,0 +1,107 @@ + +import 'dart:convert'; + +import '../io_reply.dart'; +import '../io_sender.dart'; +import '../io_tool/io_tool.dart'; +import '../io_type.dart'; +import 'package:crypto/crypto.dart' as crypto; + +import '../sm4Encipher/sm4.dart'; + +class SenderGetWifiCommand extends SenderProtocol { + + String? keyID; + String? userID; + List? token; + int? needAuthor; + List? publicKey; + List? privateKey; + + SenderGetWifiCommand({ + this.keyID, + this.userID, + this.token, + this.needAuthor, + this.publicKey, + this.privateKey, + }) : super(CommandType.generalExtendedCommond); + + @override + List messageDetail() { + List data = []; + List subData = []; + List ebcData = []; + + // 指令类型 + int type = commandType!.typeValue; + double typeDouble = type / 256; + int type1 = typeDouble.toInt(); + int type2 = type % 256; + data.add(type1); + data.add(type2); + + // 子命令类型 + data.add(53); + + // keyID 40 + int keyIDLength = utf8.encode(keyID!).length; + subData.addAll(utf8.encode(keyID!)); + subData = getFixedLengthList(subData, 40 - keyIDLength); + + //userID 20 + int userIDLength = utf8.encode(userID!).length; + subData.addAll(utf8.encode(userID!)); + subData = getFixedLengthList(subData, 20 - userIDLength); + + // token + // subData.addAll(token!); + + if(needAuthor == 0){ + //AuthCodeLen 1 + subData.add(0); + } else { + List authCodeData = []; + + //userID + authCodeData.addAll(utf8.encode(userID!)); + + //KeyID + authCodeData.addAll(utf8.encode(keyID!)); + + //token 4 首次请求 Token 填 0,如果锁需要鉴权操作者身份,则会分配动态口令并在应答消息中返回,二次请求时带上。 + authCodeData.addAll(token!); + + authCodeData.addAll(publicKey!); + + print("${commandType!.typeValue}-authCodeData:$authCodeData"); + + // 把KeyID、authUserID、时间戳、公钥通过md5加密之后就是authCode + var authCode = crypto.md5.convert(authCodeData); + + subData.add(authCode.bytes.length); + subData.addAll(authCode.bytes); + } + + data.add(subData.length); + data.addAll(subData); + + if ((data.length % 16) != 0) { + int add = (16 - data.length % 16); + for (int i = 0; i < add; i++) { + data.add(0); + } + } + print("${commandType!.typeName} SM4Data:$data"); + // 拿到数据之后通过LockId进行SM4 ECB加密 key:544d485f633335373034383064613864 + ebcData = SM4.encrypt(data, key: privateKey, mode: SM4CryptoMode.ECB); + return ebcData; + } +} + +class SenderGetWifiListReply extends Reply { + SenderGetWifiListReply.parseData(CommandType commandType, List dataDetail) + : super.parseData(commandType, dataDetail) { + data = dataDetail; + } +} diff --git a/star_lock/lib/blue/reciver_data.dart b/star_lock/lib/blue/reciver_data.dart index 7665d9d8..e2a52840 100644 --- a/star_lock/lib/blue/reciver_data.dart +++ b/star_lock/lib/blue/reciver_data.dart @@ -32,6 +32,7 @@ import 'io_protocol/io_configuringWifi.dart'; import 'io_protocol/io_getPrivateKey.dart'; import 'io_protocol/io_getPublicKey.dart'; import 'io_protocol/io_getStarLockStatusInfo.dart'; +import 'io_protocol/io_getWifiList.dart'; import 'io_protocol/io_openLock.dart'; import 'io_protocol/io_queryingFingerprintStatus.dart'; import 'io_protocol/io_referEventRecordNumber.dart'; @@ -287,6 +288,12 @@ class CommandReciverManager { SenderConfiguringWifiReply.parseData(commandType, data); } break; + case 54: + { + // 门锁搜索2.4G WIFI SSID 结果 + reply = SenderGetWifiListReply.parseData(commandType, data); + } + break; case 60: { // 注册胁迫密码 diff --git a/star_lock/lib/blue/sender_manage.dart b/star_lock/lib/blue/sender_manage.dart index b5c48e40..4793a2eb 100644 --- a/star_lock/lib/blue/sender_manage.dart +++ b/star_lock/lib/blue/sender_manage.dart @@ -20,6 +20,7 @@ import 'io_protocol/io_factoryDataReset.dart'; import 'io_protocol/io_getPrivateKey.dart'; import 'io_protocol/io_getPublicKey.dart'; import 'io_protocol/io_getStarLockStatusInfo.dart'; +import 'io_protocol/io_getWifiList.dart'; import 'io_protocol/io_openLock.dart'; import 'io_protocol/io_queryingFingerprintStatus.dart'; import 'io_protocol/io_readSupportFunctionsNoParameters.dart'; @@ -615,6 +616,27 @@ class IoSenderManage { callBack: callBack); } + //todo:wifi列表 + static void getWifiListCommand( + {required String? keyID, + required String? userID, + required List? token, + required int? needAuthor, + required List? publicKey, + required List? privateKey, + CommandSendCallBack? callBack}) { + CommandSenderManager().managerSendData( + command: SenderGetWifiCommand( + keyID: keyID, + userID: userID, + token: token, + needAuthor: needAuthor, + publicKey: publicKey, + privateKey: privateKey, + ), + callBack: callBack); + } + //todo:配置wifi static void senderConfiguringWifiCommand( {required String? keyID, diff --git a/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart b/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart index 1fa8c17d..0b8d623a 100644 --- a/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart +++ b/star_lock/lib/main/lockDetail/authorizedAdmin/authorizedAdmin/authorizedAdmin_page.dart @@ -296,7 +296,7 @@ class _AuthorizedAdminPageState extends State { Get.toNamed(Routers.sendEmailNotificationPage); } else { // _openModalBottomSheet(); - NativeInteractionTool.loadNativeShare( + NativeInteractionTool().loadNativeShare( shareText: state.pwdShareStr); } // Get.toNamed(state.emailOrPhoneController.text.contains("@")? Routers.sendEmailNotificationPage:Routers.sendEmailNotificationPage); @@ -309,7 +309,7 @@ class _AuthorizedAdminPageState extends State { btnName: '微信通知', onClick: () { // _openModalBottomSheet(); - NativeInteractionTool.loadNativeShare(shareText: state.pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText: state.pwdShareStr); }, ), SizedBox( @@ -517,13 +517,13 @@ class _AuthorizedAdminPageState extends State { case 0: //微信好友 { - NativeInteractionTool.loadNativeShare(shareText: state.pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText: state.pwdShareStr); } break; case 1: //短信 { - NativeInteractionTool.loadNativeShare(shareText: state.pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText: state.pwdShareStr); } break; case 2: @@ -535,7 +535,7 @@ class _AuthorizedAdminPageState extends State { case 3: //更多 { - NativeInteractionTool.loadNativeShare(shareText: state.pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText: state.pwdShareStr); } break; default: diff --git a/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart b/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart index 5d17f5fb..7f82f250 100644 --- a/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart +++ b/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart @@ -181,6 +181,14 @@ class _AddCardPageState extends State { Widget keyBottomWidget() { return Column( children: [ + CommonItem( + leftTitel: "是否是管理员", + rightTitle: "", + isTipsImg: false, + isHaveRightWidget: true, + rightWidget: SizedBox( + width: 60.w, height: 50.h, child: _isAdmin())), + SizedBox(height: 10.h), CommonItem( leftTitel: TranslationLoader.lanKeys!.stressCard!.tr, rightTitle: "", @@ -357,4 +365,20 @@ class _AddCardPageState extends State { }, ); } + + // 是否是管理员 + CupertinoSwitch _isAdmin() { + return CupertinoSwitch( + activeColor: CupertinoColors.activeBlue, + trackColor: CupertinoColors.systemGrey5, + thumbColor: CupertinoColors.white, + value: state.isStressFingerprint.value, + onChanged: (value) { + setState(() { + state.isStressFingerprint.value = value; + }); + }, + ); + } + } diff --git a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart index 758f0237..604c0954 100644 --- a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart +++ b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart @@ -642,14 +642,14 @@ class _SendElectronicKeyPageState extends State { //微信好友 { String pwdShareStr = '您好,您的电子钥匙生成成功'; - NativeInteractionTool.loadNativeShare(shareText: pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText: pwdShareStr); } break; case 1: //短信 { String pwdShareStr = '您好,您的电子钥匙生成成功'; - NativeInteractionTool.loadNativeShare(shareText: pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText: pwdShareStr); } break; case 2: @@ -662,7 +662,7 @@ class _SendElectronicKeyPageState extends State { //更多 { String pwdShareStr = '您好,您的电子钥匙生成成功'; - NativeInteractionTool.loadNativeShare(shareText: pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText: pwdShareStr); } break; default: diff --git a/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart b/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart index c9417af3..935b20e5 100644 --- a/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart +++ b/star_lock/lib/main/lockDetail/fingerprint/addFingerprintSelectType/addFingerprintType_page.dart @@ -181,6 +181,14 @@ class _AddFingerprintTypePageState extends State { Widget keyBottomWidget() { return Column( children: [ + CommonItem( + leftTitel: "是否是管理员", + rightTitle: "", + isTipsImg: false, + isHaveRightWidget: true, + rightWidget: SizedBox( + width: 60.w, height: 50.h, child: _isAdmin())), + SizedBox(height: 10.h), CommonItem( leftTitel: TranslationLoader.lanKeys!.stressFingerprint!.tr, rightTitle: "", @@ -337,4 +345,20 @@ class _AddFingerprintTypePageState extends State { }, ); } + + // 是否是管理员 + CupertinoSwitch _isAdmin() { + return CupertinoSwitch( + activeColor: CupertinoColors.activeBlue, + trackColor: CupertinoColors.systemGrey5, + thumbColor: CupertinoColors.white, + value: state.isStressFingerprint.value, + onChanged: (value) { + setState(() { + state.isStressFingerprint.value = value; + }); + }, + ); + } + } diff --git a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index bf43a0a8..80c81c78 100644 --- a/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/star_lock/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -1,10 +1,12 @@ import 'dart:async'; +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:intl/intl.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/keyOperationRecord/keyOperationRecord_entity.dart'; import '../../../app_settings/app_colors.dart'; @@ -44,12 +46,12 @@ class LockDetailLogic extends BaseGetXController { // } // 获取星锁状态信息 - if (reply is GetStarLockStatuInfoReply) { + if (reply is GetStarLockStatuInfoReply && state.ifCurrentScreen.value == true) { _replyGetStarLockStatusInfo(reply); } // 开完锁之后上传记录 - if (reply is SenderReferEventRecordTimeReply) { + if (reply is SenderReferEventRecordTimeReply && state.ifCurrentScreen.value == true) { _replyReferEventRecordTime(reply); } @@ -597,27 +599,31 @@ class LockDetailLogic extends BaseGetXController { // startOpenLock() { - if (state.openLockBtnState.value == 1) { - return; - } - state.iSOpenLock.value = true; - state.iSClosedUnlockSuccessfulPopup.value = false; - state.openLockBtnState.value = 1; - state.animationController.forward(); - - if (state.lockUserNo == 0) { - // 电子钥匙lockUserNo为0 要先添加用户 - addUserConnectBlue(); - } else { - print("state.isOpenLockNeedOnline.value:${state.isOpenLockNeedOnline.value}"); - if (state.isOpenLockNeedOnline.value == 0) { - // 不需要联网 - openDoorAction(1); - } else { - // 需要联网 - getLockNetToken(); + print("11111111"); + // checkBlueIsOpen((){ + print("33333333"); + if (state.openLockBtnState.value == 1) { + return; } - } + state.iSOpenLock.value = true; + state.iSClosedUnlockSuccessfulPopup.value = false; + state.openLockBtnState.value = 1; + state.animationController.forward(); + + if (state.lockUserNo == 0) { + // 电子钥匙lockUserNo为0 要先添加用户 + addUserConnectBlue(); + } else { + print("state.isOpenLockNeedOnline.value:${state.isOpenLockNeedOnline.value}"); + if (state.isOpenLockNeedOnline.value == 0) { + // 不需要联网 + openDoorAction(1); + } else { + // 需要联网 + getLockNetToken(); + } + } + // }); } startUnLock() { @@ -859,11 +865,44 @@ class LockDetailLogic extends BaseGetXController { return formattedTime; } + openBlueSet() { + if (!Platform.isIOS) { + getMicrophonePermission().then((value) { + if (!value) { + //没有权限 打开app系统设置 + openAppSettings(); + } else { + // 有权限 + } + }); + } + } + + ///请求权限 + Future getMicrophonePermission() async { + // You can request multiple permissions at once. + Map statuses = await [ + Permission.bluetoothScan, + Permission.bluetoothConnect, + Permission.location, + ].request(); + + //granted 通过,denied 被拒绝,permanentlyDenied 拒绝且不在提示 + if (statuses[Permission.bluetoothScan]!.isGranted && + statuses[Permission.bluetoothConnect]!.isGranted && + statuses[Permission.location]!.isGranted) { + return true; + } + return false; + } + @override void onReady() { // TODO: implement onReady super.onReady(); + openBlueSet(); + _initReplySubscription(); _initLockSetOpenOrCloseCheckInRefreshLockDetailWithAttendanceAction(); _scanListDiscoveredDeviceSubscriptionAction(); diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifiEntity.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifiEntity.dart similarity index 100% rename from star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifiEntity.dart rename to star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifiEntity.dart diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_logic.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart similarity index 93% rename from star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_logic.dart rename to star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart index 8bcedc1a..5df4a9c3 100644 --- a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_logic.dart @@ -7,14 +7,14 @@ import 'package:network_info_plus/network_info_plus.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/tools/baseGetXController.dart'; -import '../../../../blue/blue_manage.dart'; -import '../../../../blue/io_protocol/io_configuringWifi.dart'; -import '../../../../blue/io_reply.dart'; -import '../../../../blue/io_tool/io_tool.dart'; -import '../../../../blue/io_tool/manager_event_bus.dart'; -import '../../../../blue/sender_manage.dart'; -import '../../../../network/api_repository.dart'; -import '../../../../tools/storage.dart'; +import '../../../../../blue/blue_manage.dart'; +import '../../../../../blue/io_protocol/io_configuringWifi.dart'; +import '../../../../../blue/io_reply.dart'; +import '../../../../../blue/io_tool/io_tool.dart'; +import '../../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../../blue/sender_manage.dart'; +import '../../../../../network/api_repository.dart'; +import '../../../../../tools/storage.dart'; import 'configuringWifi_state.dart'; class ConfiguringWifiLogic extends BaseGetXController{ @@ -243,10 +243,12 @@ class ConfiguringWifiLogic extends BaseGetXController{ // TODO: implement onReady super.onReady(); - getWifiName().then((value) { - print("wifiName:$value"); - state.wifiNameController.text = value; - }); + if(state.wifiName.value.isEmpty){ + getWifiName().then((value) { + print("wifiName:$value"); + state.wifiNameController.text = value; + }); + } getWifiLockServiceIpAndPort(); _initReplySubscription(); diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_page.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_page.dart similarity index 92% rename from star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_page.dart rename to star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_page.dart index 13b3a49e..c9f7cd5b 100644 --- a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_page.dart +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_page.dart @@ -4,13 +4,13 @@ import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; -import '../../../../app_settings/app_colors.dart'; -import '../../../../blue/blue_manage.dart'; -import '../../../../tools/appRouteObserver.dart'; -import '../../../../tools/commonItem.dart'; -import '../../../../tools/submitBtn.dart'; -import '../../../../tools/titleAppBar.dart'; -import '../../../../translations/trans_lib.dart'; +import '../../../../../app_settings/app_colors.dart'; +import '../../../../../blue/blue_manage.dart'; +import '../../../../../tools/appRouteObserver.dart'; +import '../../../../../tools/commonItem.dart'; +import '../../../../../tools/submitBtn.dart'; +import '../../../../../tools/titleAppBar.dart'; +import '../../../../../translations/trans_lib.dart'; import 'configuringWifi_logic.dart'; class ConfiguringWifiPage extends StatefulWidget { diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_state.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_state.dart similarity index 79% rename from star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_state.dart rename to star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_state.dart index e096a7ca..ec9b3161 100644 --- a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi_state.dart +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifi_state.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import '../lockSet/lockSetInfo_entity.dart'; +import '../../lockSet/lockSetInfo_entity.dart'; import 'configuringWifiEntity.dart'; class ConfiguringWifiState{ @@ -10,6 +10,7 @@ class ConfiguringWifiState{ var lockSetInfoData = LockSetInfoData().obs; var lockBasicInfo = LockBasicInfo().obs; + var wifiName = "".obs; var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 var sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用) @@ -19,6 +20,10 @@ class ConfiguringWifiState{ var map = Get.arguments; lockSetInfoData.value = map["lockSetInfoData"]; lockBasicInfo.value = lockSetInfoData.value.lockBasicInfo!; + if ((map["wifiName"] != null)) { + wifiName.value = map["wifiName"]; + wifiNameController.text = wifiName.value; + } } } \ No newline at end of file diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart new file mode 100644 index 00000000..87507230 --- /dev/null +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_logic.dart @@ -0,0 +1,157 @@ + +import 'dart:async'; + +import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; +import 'package:get/get.dart'; +import 'package:star_lock/blue/io_protocol/io_getWifiList.dart'; +import 'package:star_lock/tools/baseGetXController.dart'; + +import '../../../../../blue/blue_manage.dart'; +import '../../../../../blue/io_reply.dart'; +import '../../../../../blue/io_tool/io_tool.dart'; +import '../../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../../blue/sender_manage.dart'; +import '../../../../../tools/storage.dart'; +import 'wifiList_state.dart'; + +class WifiListLogic extends BaseGetXController { + final WifiListState state = WifiListState(); + + // 获取解析后的数据 + late StreamSubscription _replySubscription; + void _initReplySubscription() { + _replySubscription = EventBusManager().eventBus!.on().listen((reply) { + if(reply is SenderGetWifiListReply) { + _replyGetWifiListParameters(reply); + } + }); + } + + // 设置自动落锁数据解析 + Future _replyGetWifiListParameters(Reply reply) async { + int status = reply.data[2]; + switch(status){ + case 0x00: + //成功 + print("${reply.commandType}数据解析成功"); + // showEasyLoading(); + Future.delayed(4.seconds, (){ + dismissEasyLoading(); + }); + state.sureBtnState.value = 0; + cancelBlueConnetctToastTimer(); + + if (reply.data[6] > 0) { + reply.data.removeRange(0, 7); + // 把得到的数据按33位分割成数组 然后塞进一个新的数组里面 + var getList = splitList(reply.data, 33); + // print("getList:$getList"); + var uploadList = >[]; + for (int i = 0; i < getList.length; i++) { + var indexList = getList[i]; + // print("indexList:$indexList"); + var indexMap = {}; + var wifiName = indexList.sublist(0, 32); + // print("wifiName:$wifiName"); + indexMap["wifiName"] = utf8String(wifiName); + indexMap["rssi"] = (indexList.last - 255).toString(); + uploadList.add(indexMap); + state.wifiNameDataList.value = uploadList; + } + // print("reply.data:${reply.data} getList:$getList}"); + } + + break; + case 0x06: + //无权限 + print("${reply.commandType}需要鉴权"); + + break; + case 0x07: + //无权限 + print("${reply.commandType}用户无权限"); + + break; + case 0x09: + // 权限校验错误 + print("${reply.commandType}权限校验错误"); + + break; + default: + //失败 + print("${reply.commandType}失败"); + + break; + } + } + + // 获取wifi列表 + Future senderGetWifiListWifiAction() async { + if(state.sureBtnState.value == 1){ + return; + } + state.sureBtnState.value = 1; + + showEasyLoading(); + showBlueConnetctToastTimer(action: (){ + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { + if (connectionState == DeviceConnectionState.connected){ + var token = await Storage.getStringList(saveBlueToken); + List getTokenList = changeStringListToIntList(token!); + print("openDoorTokenPubToken:$getTokenList"); + + var privateKey = await Storage.getStringList(saveBluePrivateKey); + List getPrivateKeyList = changeStringListToIntList(privateKey!); + + var publicKey = await Storage.getStringList(saveBluePublicKey); + List publicKeyDataList = changeStringListToIntList(publicKey!); + + IoSenderManage.getWifiListCommand( + keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), + userID: await Storage.getUid(), + token: getTokenList, + needAuthor: 1, + publicKey: publicKeyDataList, + privateKey: getPrivateKeyList, + ); + } else if (connectionState == DeviceConnectionState.disconnected) { + dismissEasyLoading(); + state.sureBtnState.value = 0; + cancelBlueConnetctToastTimer(); + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + } + }); + } + + @override + void onReady() { + // TODO: implement onReady + super.onReady(); + print("onReady()"); + + _initReplySubscription(); + + } + + @override + void onInit() { + // TODO: implement onInit + super.onInit(); + print("onInit()"); + + senderGetWifiListWifiAction(); + } + + @override + void onClose() { + // TODO: implement onClose + super.onClose(); + _replySubscription.cancel(); + } + +} \ No newline at end of file diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_page.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_page.dart new file mode 100644 index 00000000..5faa9977 --- /dev/null +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_page.dart @@ -0,0 +1,127 @@ + +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; + +import '../../../../../appRouters.dart'; +import '../../../../../app_settings/app_colors.dart'; +import '../../../../../tools/noData.dart'; +import '../../../../../tools/submitBtn.dart'; +import '../../../../../tools/titleAppBar.dart'; +import 'wifiList_logic.dart'; + +class WifiListPage extends StatefulWidget { + const WifiListPage({Key? key}) : super(key: key); + + @override + State createState() => _WifiListPageState(); +} + +class _WifiListPageState extends State { + final logic = Get.put(WifiListLogic()); + final state = Get.find().state; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.white, + appBar: TitleAppBar( + barTitle: "WIFI列表", + haveBack: true, + actionsList: [ + TextButton( + child: Text( + "刷新", style: TextStyle(color: Colors.white, fontSize: 24.sp), + ), + onPressed: () { + logic.senderGetWifiListWifiAction(); + }, + ), + ], + backgroundColor: AppColors.mainColor), + body: Column( + children: [ + Expanded( + child: Obx(() => state.wifiNameDataList.value.isNotEmpty ? ListView.builder( + itemCount: state.wifiNameDataList.value.length, + itemBuilder: (c, index) { + Map wifiNameStr = state.wifiNameDataList.value[index]; + return _messageListItem(wifiNameStr["wifiName"], wifiNameStr["rssi"], () { + Get.toNamed(Routers.configuringWifiPage, arguments: { + 'lockSetInfoData': state.lockSetInfoData.value, + 'wifiName': wifiNameStr["wifiName"], + }); + }); + }) : NoData(noDataHeight: 1.sh - ScreenUtil().statusBarHeight - ScreenUtil().bottomBarHeight - 64.h)), + ), + SubmitBtn( + btnName: "手动配网", + fontSize: 28.sp, + borderRadius: 20.w, + padding: EdgeInsets.only(top: 25.w, bottom: 25.w), + onClick: () { + Get.toNamed(Routers.configuringWifiPage, arguments: { + 'lockSetInfoData': state.lockSetInfoData.value + }); + }), + SizedBox( + height: 64.h, + ) + ], + ) + ); + } + + Widget _messageListItem(String wifiName, String rssi, Function() action) { + return GestureDetector( + onTap: action, + child: Container( + height: 90.h, + width: 1.sw, + margin: EdgeInsets.only(bottom: 2.h), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10.w), + ), + child: Container( + width: 1.sw, + height: 80.h, + margin: EdgeInsets.only(left: 20.w, right: 40.w), + child: Column( + children: [ + SizedBox( + height: 79.h, + width: 1.sw - 20.w*2, + child: Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + child: Text( + "$wifiName(${rssi}db)", + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 22.sp, color: AppColors.blackColor), + ), + ), + // Text( + // rssi, + // maxLines: 1, + // overflow: TextOverflow.ellipsis, + // style: TextStyle( + // fontSize: 22.sp, color: AppColors.blackColor), + // ) + ], + ), + ), + Container( + height: 1.h, + color: AppColors.greyLineColor, + ), + ], + ), + ), + ), + ); + } +} diff --git a/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_state.dart b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_state.dart new file mode 100644 index 00000000..698501f2 --- /dev/null +++ b/star_lock/lib/main/lockDetail/lockSet/configuringWifi/wifiList/wifiList_state.dart @@ -0,0 +1,18 @@ + +import 'package:get/get.dart'; + +import '../../lockSet/lockSetInfo_entity.dart'; + +class WifiListState{ + final wifiNameDataList = >[].obs; + var lockSetInfoData = LockSetInfoData().obs; + var lockBasicInfo = LockBasicInfo().obs; + + var ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + var sureBtnState = 0.obs;// 0普通状态(可用) 1连接中(不可用) + WifiListState() { + var map = Get.arguments; + lockSetInfoData.value = map["lockSetInfoData"]; + lockBasicInfo.value = lockSetInfoData.value.lockBasicInfo!; + } +} \ No newline at end of file diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart index 6580fc5b..415dc92a 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_logic.dart @@ -269,7 +269,7 @@ class LockSetLogic extends BaseGetXController { showBlueConnetctToastTimer(isShowBlueConnetctToast: false, action: (){ dismissEasyLoading(); // print("1111111"); - showDeletAlertTipDialog(Get.context!); + showDeletAlertTipDialog(); }); BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { @@ -299,7 +299,7 @@ class LockSetLogic extends BaseGetXController { cancelBlueConnetctToastTimer(); print("222222"); if(state.ifCurrentScreen.value == true){ - showDeletAlertTipDialog(Get.context!); + showDeletAlertTipDialog(); } } }); @@ -311,7 +311,7 @@ class LockSetLogic extends BaseGetXController { showBlueConnetctToastTimer(isShowBlueConnetctToast: false, action: (){ dismissEasyLoading(); print("333333"); - showDeletAlertTipDialog(Get.context!); + showDeletAlertTipDialog(); }); BlueManage().bludSendData(BlueManage().connectDeviceName, (DeviceConnectionState connectionState) async { if (connectionState == DeviceConnectionState.connected) { @@ -337,7 +337,7 @@ class LockSetLogic extends BaseGetXController { cancelBlueConnetctToastTimer(); print("444444"); if(state.ifCurrentScreen.value == true){ - showDeletAlertTipDialog(Get.context!); + showDeletAlertTipDialog(); } } }); @@ -564,7 +564,7 @@ class LockSetLogic extends BaseGetXController { BlueManage().stopScan(); dismissEasyLoading(); print("555555"); - showDeletAlertTipDialog(Get.context!); + showDeletAlertTipDialog(); }else{ // 每秒判断获取是否搜到了当前设备 if (state.currentDeviceUUid.isNotEmpty) { @@ -612,7 +612,7 @@ class LockSetLogic extends BaseGetXController { }else if(state.currentDeviceUUid.value[31] == "0"){ // 未配对 表示这把锁已被强制初始化 处于可添加状态 直接弹窗删除即可 print("666666"); - showDeletAlertTipDialog(Get.context!); + showDeletAlertTipDialog(showContent:"当前锁已被强制初始化,可直接添加。"); } } @@ -700,31 +700,34 @@ class LockSetLogic extends BaseGetXController { }); } - void showDeletAlertTipDialog(BuildContext context) { + void showDeletAlertTipDialog({String? showContent = ""}) { + bool isContains = BlueManage().connectDeviceName!.contains("T9A"); + var content = showContent!.isEmpty ? "删除设备失败,请确保在设备附近,设备未被连接,设备已打开${isContains == true ? "。如果是全自动锁,请使屏幕变亮" : ""}" : showContent; showCupertinoDialog( - context: context, + context: Get.context!, builder: (context) { return CupertinoAlertDialog( title: const Text("提示"), - content: const Text('删除门锁后如需重新添加需要在门锁设置的"蓝牙功能"选项下先"清除配对",确定吗?'), + content: Text(content), + // content: const Text('删除门锁后如需重新添加需要在门锁设置的"蓝牙功能"选项下先"清除配对",确定吗?'), actions: [ - CupertinoDialogAction( - child: Text(TranslationLoader.lanKeys!.cancel!.tr), - onPressed: () { - Navigator.pop(context); - }, - ), + // CupertinoDialogAction( + // child: Text(TranslationLoader.lanKeys!.cancel!.tr), + // onPressed: () { + // Navigator.pop(context); + // }, + // ), CupertinoDialogAction( child: Text(TranslationLoader.lanKeys!.sure!.tr), onPressed: () { Navigator.pop(context); - if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { - // 直接调用删除锁接口 - deletLockInfoData(); - } else { - // 直接调用删除要是接口 - deletKeyData(); - } + // if (state.lockSetInfoData.value.lockBasicInfo!.isLockOwner == 1) { + // // 直接调用删除锁接口 + // deletLockInfoData(); + // } else { + // // 直接调用删除要是接口 + // deletKeyData(); + // } }, ), ], diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart index a0ccf33f..5a4cf587 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart @@ -525,9 +525,12 @@ class _LockSetPageState extends State with RouteAware { isHaveLine: true, isHaveDirection: true, action: () { - Get.toNamed(Routers.configuringWifiPage, arguments: { + Get.toNamed(Routers.wifiListPage, arguments: { 'lockSetInfoData': state.lockSetInfoData.value }); + // Get.toNamed(Routers.configuringWifiPage, arguments: { + // 'lockSetInfoData': state.lockSetInfoData.value + // }); })), ), // Obx(() => diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart index 14213d9c..cf5dabd8 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyDetail/passwordKeyDetail_page.dart @@ -319,13 +319,13 @@ class _PasswordKeyDetailPageState extends State { case 0: //微信好友 { - NativeInteractionTool.loadNativeShare(shareText:pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText:pwdShareStr); } break; case 1: //短信 { - NativeInteractionTool.loadNativeShare(shareText:pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText:pwdShareStr); } break; case 2: @@ -337,7 +337,7 @@ class _PasswordKeyDetailPageState extends State { case 3: //更多 { - NativeInteractionTool.loadNativeShare(shareText:pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText:pwdShareStr); } break; default: diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart index 2d476fc5..982c858d 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart @@ -682,13 +682,13 @@ class _PasswordKeyPerpetualPageState extends State wit case 0: //微信好友 { - NativeInteractionTool.loadNativeShare(shareText:pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText:pwdShareStr); } break; case 1: //短信 { - NativeInteractionTool.loadNativeShare(shareText:pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText:pwdShareStr); } break; case 2: @@ -700,7 +700,7 @@ class _PasswordKeyPerpetualPageState extends State wit case 3: //更多 { - NativeInteractionTool.loadNativeShare(shareText:pwdShareStr); + NativeInteractionTool().loadNativeShare(shareText:pwdShareStr); } break; default: diff --git a/star_lock/lib/main/lockMian/lockMain/lockMain_page.dart b/star_lock/lib/main/lockMian/lockMain/lockMain_page.dart index 6b25e7de..8975132a 100644 --- a/star_lock/lib/main/lockMian/lockMain/lockMain_page.dart +++ b/star_lock/lib/main/lockMian/lockMain/lockMain_page.dart @@ -43,11 +43,20 @@ class _StarLockMainPageState extends State with BaseWidget { @override void initState() { super.initState(); - - getHttpData(); + // WidgetsBinding.instance!.addPostFrameCallback((_) { + // getHttpData(); + // }); initAliyunPush(); } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + WidgetsBinding.instance!.addPostFrameCallback((_) { + getHttpData(); + }); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -125,14 +134,12 @@ class _StarLockMainPageState extends State with BaseWidget { Storage.setBool(ifIsDemoModeOrNot, false); returnWidget = LockDetailPage( isOnlyOneData: true, - lockListInfoItemEntity: state - .lockListInfoEntity.value.data!.groupList![0].lockList![0]); + lockListInfoItemEntity: state.lockListInfoEntity.value.data!.groupList![0].lockList![0]); break; case 2: // 有多条数据 Storage.setBool(ifIsDemoModeOrNot, false); - returnWidget = LockListPage( - lockListInfoGroupEntity: state.lockListInfoEntity.value.data!); + returnWidget = LockListPage(lockListInfoGroupEntity: state.lockListInfoEntity.value.data!); break; default: returnWidget = NoData(); diff --git a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart index 4b6718a0..505a0739 100644 --- a/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart +++ b/star_lock/lib/mine/addLock/nearbyLock/nearbyLock_logic.dart @@ -354,6 +354,7 @@ class NearbyLockLogic extends BaseGetXController { } void stopScanBlueList(){ + BlueManage().disconnect("state.selectLockName.value"); BlueManage().stopScan(); } diff --git a/star_lock/lib/mine/message/messageList/messageList_logic.dart b/star_lock/lib/mine/message/messageList/messageList_logic.dart index 044c8781..b5de2944 100644 --- a/star_lock/lib/mine/message/messageList/messageList_logic.dart +++ b/star_lock/lib/mine/message/messageList/messageList_logic.dart @@ -7,6 +7,7 @@ import '../../../tools/eventBusEventManage.dart'; import 'messageList_entity.dart'; import 'messageList_state.dart'; +typedef BlockDeletSuccssCallback = void Function(); class MessageListLogic extends BaseGetXController { final MessageListState state = MessageListState(); @@ -31,18 +32,19 @@ class MessageListLogic extends BaseGetXController { } // 删除消息 - void deletMessageDataRequest(String messageId) async { + void deletMessageDataRequest(String messageId, BlockDeletSuccssCallback blockDeletSuccssCallback) async { MessageListEntity entity = await ApiRepository.to.deletMessageLoadData(messageId:messageId); if (entity.errorCode!.codeIsSuccessful) { - messageListDataRequest(); + blockDeletSuccssCallback(); } } - /// 刷新密码列表 + /// 刷新消息列表 StreamSubscription? _readMessageRefreshUIEvent; void _readMessageRefreshUIAction() { // 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus _readMessageRefreshUIEvent = eventBus.on().listen((event) { + pageNo == 1; messageListDataRequest(); }); } diff --git a/star_lock/lib/mine/message/messageList/messageList_page.dart b/star_lock/lib/mine/message/messageList/messageList_page.dart index 8fcaf6c9..2f747938 100644 --- a/star_lock/lib/mine/message/messageList/messageList_page.dart +++ b/star_lock/lib/mine/message/messageList/messageList_page.dart @@ -69,7 +69,10 @@ class _MessageListPageState extends State with TickerProviderSt children: [ SlidableAction( onPressed: (BuildContext context){ - logic.deletMessageDataRequest(messageItemEntity.id!); + logic.deletMessageDataRequest(messageItemEntity.id!, (){ + logic.pageNo = 1; + getHttpData(); + }); }, backgroundColor: Colors.red, foregroundColor: Colors.white, diff --git a/star_lock/lib/network/api_repository.dart b/star_lock/lib/network/api_repository.dart index a61425ab..56a1d80e 100644 --- a/star_lock/lib/network/api_repository.dart +++ b/star_lock/lib/network/api_repository.dart @@ -35,7 +35,7 @@ import '../main/lockDetail/checkingIn/checkingInStaff/checkingInSetAddStaff/chec import '../main/lockDetail/checkingIn/checkingInStaff/checkingInSetStaffList/checkingInStaffList_entity.dart'; import '../main/lockDetail/fingerprint/addFingerprint/addFingerprint_entity.dart'; import '../main/lockDetail/fingerprint/fingerprintList/fingerprintListData_entity.dart'; -import '../main/lockDetail/lockSet/configuringWifi/configuringWifiEntity.dart'; +import '../main/lockDetail/lockSet/configuringWifi/configuringWifi/configuringWifiEntity.dart'; import '../main/lockDetail/lockSet/lockSet/checkingInInfoData_entity.dart'; import '../main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import '../main/lockDetail/lockSet/lockTime/getServerDatetime_entity.dart'; diff --git a/star_lock/lib/tools/NativeInteractionTool.dart b/star_lock/lib/tools/NativeInteractionTool.dart index 94d08f9d..1f187ea4 100644 --- a/star_lock/lib/tools/NativeInteractionTool.dart +++ b/star_lock/lib/tools/NativeInteractionTool.dart @@ -3,15 +3,41 @@ import 'package:flutter/services.dart'; ///原生交互配置 class NativeInteractionConfig{ - static String eventChannel = 'starLockFlutterReceive'; - static String methodChannel = 'starLockFlutterSend'; + static String methodSendChannel = 'starLockFlutterSend'; + static String receiveEventChannel = 'starLockFlutterReceive'; } ///原生交互flutter向原生发送消息 +typedef BlockBlueStatus = void Function(String status); class NativeInteractionTool{ + var sendChannel = MethodChannel(NativeInteractionConfig.methodSendChannel); + var receiveChannel = MethodChannel(NativeInteractionConfig.receiveEventChannel); - static loadNativeShare({required String shareText}){ - MethodChannel(NativeInteractionConfig.methodChannel).invokeMethod('loadNativeShare', {'shareText':shareText}); + ///加载原生分享 + loadNativeShare({required String shareText}){ + sendChannel.invokeMethod('loadNativeShare', {'shareText':shareText}); + } + + ///获取设备蓝牙状态 + sendGetBlueStatus(){ + sendChannel.invokeMethod('sendGetBlueStatus'); + } + + ///获取设备蓝牙是否打开 + receiveChannelBlueIsOnEvent(BlockBlueStatus blockBlueStatus){ + receiveChannel.setMethodCallHandler((MethodCall call) async { + print('收到原生发送的信息call.method: ${call.method} call.arguments:${call.arguments}'); + switch (call.method) { + case 'getBlueStatus': + // 获取设备蓝牙开启/关闭状态 + final String message = call.arguments; + blockBlueStatus(message); + print('收到原生发送的信息getBlueStatus: $message'); + break; + default: + throw MissingPluginException(); + } + }); } } diff --git a/star_lock/lib/tools/baseGetXController.dart b/star_lock/lib/tools/baseGetXController.dart index dc9d0190..c8af06d9 100644 --- a/star_lock/lib/tools/baseGetXController.dart +++ b/star_lock/lib/tools/baseGetXController.dart @@ -1,13 +1,19 @@ import 'dart:async'; +import 'dart:io'; +import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/blue/blue_manage.dart'; +import 'package:system_settings/system_settings.dart'; +import 'package:url_launcher/url_launcher.dart'; import '../common/XSConstantMacro/XSConstantMacro.dart'; +import 'NativeInteractionTool.dart'; import 'manager/client_manager.dart'; +import 'showIosTipView.dart'; class BaseGetXController extends GetxController{ int currentTimeSeconds = 0; @@ -119,6 +125,51 @@ class BaseGetXController extends GetxController{ Get.offAllNamed(Routers.starLockLoginPage); } + void checkBlueIsOpen(void Function() action) { + NativeInteractionTool().sendGetBlueStatus(); + NativeInteractionTool().receiveChannelBlueIsOnEvent((String status) { + print("22222222"); + if(status == "1"){ + // 蓝牙已打开 + Get.log('蓝牙已打开'); + action(); + }else if(status == "0"){ + // 蓝牙未打开 + Get.log('蓝牙未打开'); + showIosTipViewDialog(); + return; + }else{ + // 蓝牙未打开 + Get.log('设备不支持蓝牙'); + showToast("设备不支持蓝牙"); + return; + } + }); + } + + void showIosTipViewDialog() { + showDialog( + context: Get.context!, + builder: (BuildContext context) { + return ShowIosTipView( + title: "提示", + tipTitle: "蓝牙未打开,请到设置里面打开蓝牙", + sureClick: () { + Get.back(); + if (Platform.isIOS) { + launch('App-Prefs:'); + }else{ + SystemSettings.system(); + } + }, + cancelClick: () { + Get.back(); + }, + ); + } + ); + } + String getUseKeyTypeStr(int? startDate, int? endDate,int? keyType) { String useDateStr = ''; if (keyType == XSConstantMacro.keyTypeTime) { diff --git a/star_lock/pubspec.yaml b/star_lock/pubspec.yaml index fe4dc2b9..ce765f7e 100644 --- a/star_lock/pubspec.yaml +++ b/star_lock/pubspec.yaml @@ -74,7 +74,7 @@ dependencies: camera: ^0.10.5+5 path_provider: ^2.1.0 #跳转到外部 - url_launcher: ^6.1.12 + url_launcher: ^6.1.10 #蓝牙 flutter_reactive_ble: ^5.1.1 # @@ -115,7 +115,7 @@ dependencies: aliyun_push: ^0.1.6 #视频播放器 - video_player: ^2.7.2 + video_player: ^2.7.1 #控制横竖屏控件 auto_orientation: ^2.3.1 audioplayers: ^5.2.1 @@ -140,6 +140,7 @@ dependencies: #侧滑删除 flutter_slidable: ^3.0.1 + system_settings: ^2.0.0 dev_dependencies: flutter_test: sdk: flutter From 52e700ad57789d39976dfcbb7bef9bf900ca82af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=B0=91=E9=98=B3?= <786612630@qq.com> Date: Sat, 9 Mar 2024 18:00:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/star_lock/pubspec.yaml b/star_lock/pubspec.yaml index 35f3889b..ebc53a0f 100644 --- a/star_lock/pubspec.yaml +++ b/star_lock/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.11+20240306 +version: 1.0.11+20240309 environment: sdk: '>=2.12.0 <3.0.0'