From ca00faad0b87018e778a25cc37dd6521655d987b Mon Sep 17 00:00:00 2001 From: qmqz Date: Fri, 3 Apr 2026 15:07:25 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0=E7=9C=A0=E8=8A=B1=E7=B3=96?= =?UTF-8?q?ios=E6=8E=A7=E5=88=B6=E9=A1=B5=E7=A9=BA=E7=99=BD=202.=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dios=E9=A6=96=E9=A1=B5=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=8E=A7=E5=88=B6=E6=97=A0=E6=95=88=E6=9E=9C?= =?UTF-8?q?=203.=E4=BF=AE=E5=A4=8Dios=E6=89=AB=E6=8F=8F=E8=93=9D=E7=89=99?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device_bind/blueteeth_device_page.dart | 20 +- .../device/mht_blueteeth_device_page.dart | 20 +- .../component/HomeDeviceStausWidget.dart | 34 +- lib/pages/mh_page/test/WebviewTestModel.dart | 327 ++++++++---------- 4 files changed, 195 insertions(+), 206 deletions(-) diff --git a/lib/pages/device_bind/blueteeth_device_page.dart b/lib/pages/device_bind/blueteeth_device_page.dart index d122ee2..a5b2f90 100644 --- a/lib/pages/device_bind/blueteeth_device_page.dart +++ b/lib/pages/device_bind/blueteeth_device_page.dart @@ -61,7 +61,7 @@ class _BlueteethDevicePageState extends State { Get.find().startStatusPolling(); blueteethBindController.search.value = ""; blueteethBindController.currentDeviceMac?.value = ""; - BluetoothHelper.listenBluetoothState((isOn) { + BluetoothHelper.listenBluetoothState((isOn) async { blueteethBindController.model.bluetooth = isOn; if (isOn) { isScanning = false; @@ -69,13 +69,17 @@ class _BlueteethDevicePageState extends State { } blueteethBindController.updateAll(); if (!isOn && !_isDialogShowing) { - _isDialogShowing = true; - blueteethBindController.model.devicelist = []; - blueteethBindController.model.betDevicelist = []; - blueteethBindController.updateAll(); - _showBluetoothNotEnabledDialog().then((_) { - _isDialogShowing = false; - }); + await Future.delayed(Duration(seconds: 2)); + bool isReallyOn = await FlutterBluePlus.isOn; + if (!isReallyOn) { + _isDialogShowing = true; + blueteethBindController.model.devicelist = []; + blueteethBindController.model.betDevicelist = []; + blueteethBindController.updateAll(); + _showBluetoothNotEnabledDialog().then((_) { + _isDialogShowing = false; + }); + } } }); } diff --git a/lib/pages/mh_page/device/mht_blueteeth_device_page.dart b/lib/pages/mh_page/device/mht_blueteeth_device_page.dart index d2ef8b6..a836a08 100644 --- a/lib/pages/mh_page/device/mht_blueteeth_device_page.dart +++ b/lib/pages/mh_page/device/mht_blueteeth_device_page.dart @@ -63,18 +63,22 @@ class _MHTBlueteethDevicePageState extends State { mhtBlueToothController.startStatusPolling(); mhtBlueToothController.search.value = ""; mhtBlueToothController.currentDeviceMac?.value = ""; - BluetoothHelper.listenBluetoothState((isOn) { + BluetoothHelper.listenBluetoothState((isOn) async { mhtBlueToothController.model.bluetooth = isOn; mhtBlueToothController.updateAll(); if (!isOn && !_isDialogShowing) { - _isDialogShowing = true; - mhtBlueToothController.model.blueRawData = []; - mhtBlueToothController.model.deviceDataStatus = []; - mhtBlueToothController.updateAll(); - _showBluetoothNotEnabledDialog().then((_) { - _isDialogShowing = false; - }); + await Future.delayed(Duration(seconds: 2)); + bool isReallyOn = await FlutterBluePlus.isOn; + if (!isReallyOn) { + _isDialogShowing = true; + mhtBlueToothController.model.blueRawData = []; + mhtBlueToothController.model.deviceDataStatus = []; + mhtBlueToothController.updateAll(); + _showBluetoothNotEnabledDialog().then((_) { + _isDialogShowing = false; + }); + } } }); } diff --git a/lib/pages/mh_page/homepage/component/HomeDeviceStausWidget.dart b/lib/pages/mh_page/homepage/component/HomeDeviceStausWidget.dart index 5dcec22..6adf712 100644 --- a/lib/pages/mh_page/homepage/component/HomeDeviceStausWidget.dart +++ b/lib/pages/mh_page/homepage/component/HomeDeviceStausWidget.dart @@ -238,24 +238,28 @@ Future checkBlueToothPermissin() async { var locationGranted; if (Platform.isIOS) { - PermissionStatus isBleGranted = await Permission.bluetooth.request(); - if (!isBleGranted.isGranted) { - // startBluetoothScanning(); - await FlutterBluePlus.startScan(timeout: Duration(seconds: 10)); - data = { - 'bluetoothScanGranted': true, - 'bluetoothConnectGranted': true, - }; - } else { - try { + try { + PermissionStatus isBleGranted = await Permission.bluetooth.request(); + if (!isBleGranted.isGranted) { + // startBluetoothScanning(); await FlutterBluePlus.startScan(timeout: Duration(seconds: 10)); - } catch (e) { - TopSlideNotification.show(Get.context!, - text: "蓝牙权限未开启,请在设置中开启蓝牙权限".tr, - textColor: themeController.currentColor.sc9); + data = { + 'bluetoothScanGranted': true, + 'bluetoothConnectGranted': true, + }; + } else { + try { + await FlutterBluePlus.startScan(timeout: Duration(seconds: 10)); + } catch (e) { + TopSlideNotification.show(Get.context!, + text: "蓝牙权限未开启,请在设置中开启蓝牙权限".tr, + textColor: themeController.currentColor.sc9); + } } + return data; + } catch (e) { + ef.log("${e.toString()}"); } - return data; } else { try { // 先显示权限说明弹窗(同屏显示) diff --git a/lib/pages/mh_page/test/WebviewTestModel.dart b/lib/pages/mh_page/test/WebviewTestModel.dart index 4a88bf9..7f96c78 100644 --- a/lib/pages/mh_page/test/WebviewTestModel.dart +++ b/lib/pages/mh_page/test/WebviewTestModel.dart @@ -54,7 +54,7 @@ class WebviewTestController extends GetControllerEx { ), settings: buildsettings(), params: PlatformHeadlessInAppWebViewCreationParams( - onLoadStop: (controller, url) { + onLoadStop: (controller, url) async { setState(() { ready.value = true; }); @@ -64,6 +64,9 @@ class WebviewTestController extends GetControllerEx { // ef.log("[请求资源时间]${web.requestTimestamp}"); // _startMonitoringIfNeeded(); }, + initialSettings: InAppWebViewSettings( + allowsBackForwardNavigationGestures: false, // 禁用侧滑返回/前进手势 + ), ), ); try { @@ -617,186 +620,160 @@ class WebviewTestView extends GetComponent { final mainAxisAlignment = showWeb ? MainAxisAlignment.start : MainAxisAlignment.center; - return Scaffold( - backgroundColor: Colors.transparent, - body: Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: mainAxisAlignment, - children: [ - // 未登录提示 - if (!isLoggedIn) - Center( - child: InkWell( - onTap: () => Get.toNamed("/loginPage"), - child: RichText( - text: TextSpan( - children: [ - TextSpan( - text: "请先".tr, - style: TextStyle( - color: Colors.white, - fontSize: 30.rpx, - ), - ), - WidgetSpan( - child: Stack( - children: [ - Text( - "登录".tr, - style: TextStyle( - color: stringToColor("#84F5FF"), - fontSize: 30.rpx, - ), + return PopScope( + canPop: false, // 完全禁止页面返回 + onPopInvoked: (didPop) async { + if (didPop) return; + }, + child: Scaffold( + backgroundColor: Colors.transparent, + body: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: mainAxisAlignment, + children: [ + // 未登录提示 + if (!isLoggedIn) + Center( + child: InkWell( + onTap: () => Get.toNamed("/loginPage"), + child: RichText( + text: TextSpan( + children: [ + TextSpan( + text: "请先".tr, + style: TextStyle( + color: Colors.white, + fontSize: 30.rpx, ), - Positioned( - bottom: 0, - left: 0, - right: 0, - child: Container( - height: 1, - color: stringToColor("#84F5FF"), - ), - ), - ], - ), - ), - TextSpan( - text: "后,再进行设备控制".tr, - style: TextStyle( - color: Colors.white, - fontSize: 30.rpx, - ), - ), - ], - ), - ), - ), - ), - - // 已登录但无设备提示 - if (isLoggedIn && !hasDevice) - Center( - child: InkWell( - onTap: () => Get.toNamed("/mHTDeviceTypePage"), - child: RichText( - text: TextSpan( - children: [ - TextSpan( - text: "请先".tr, - style: TextStyle( - color: Colors.white, - fontSize: 30.rpx, - ), - ), - WidgetSpan( - child: Stack( - children: [ - Text( - "绑定设备".tr, - style: TextStyle( - color: stringToColor("#84F5FF"), - fontSize: 30.rpx, - ), - ), - Positioned( - bottom: 0, - left: 0, - right: 0, - child: Container( - height: 1, - color: stringToColor("#84F5FF"), - ), - ), - ], - ), - ), - TextSpan( - text: "后,再进行设备控制".tr, - style: TextStyle( - color: Colors.white, - fontSize: 30.rpx, - ), - ), - ], - ), - ), - ), - ), - - // 显示 WebView - if (showWeb) - Expanded( - child: Align( - alignment: Alignment.topLeft, - child: Obx(() { - // return (controller.ready.value && (MainPageBBottomChange.getCurrentIndex() == 2)) - // return (controller.ready.value && (MainPageBBottomChange.getCurrentIndex() == 2)&& controller.loadRecource.value == true) - // return Stack(children: [ - // controller.ready.value - // ? controller.web.build() - // : Container(), - // Text("1222121212"), - // ]); - // return Stack( - // children: [ - // controller.ready.value - // ? controller.web.build() - // : Container(), - - // // 只有 loadRecource == false 时才显示覆盖文字 - // if (!controller.loadRecource.value) - // Positioned.fill( - // child: Container( - // color: Colors.black54, // 半透明遮罩,可选 - // alignment: Alignment.center, - // child: Text( - // "资源加载中...", - // style: TextStyle( - // color: Colors.red, - // fontSize: 30.rpx, - // fontWeight: FontWeight.bold, - // ), - // ), - // ), - // ), - // ], - // ); - return Stack( - children: [ - controller.ready.value - ? controller.web.build() - : Container(), - if (!controller.loadRecource.value) - Positioned.fill( - child: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage( - 'assets/images/new_background.png'), - fit: BoxFit.fill, - ), - ), - alignment: Alignment.center, - child: Column( - mainAxisSize: MainAxisSize.min, + ), + WidgetSpan( + child: Stack( children: [ - CircularProgressIndicator( - valueColor: AlwaysStoppedAnimation( - Colors.white), + Text( + "登录".tr, + style: TextStyle( + color: stringToColor("#84F5FF"), + fontSize: 30.rpx, + ), + ), + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Container( + height: 1, + color: stringToColor("#84F5FF"), + ), ), ], ), ), - ), - ], - ); - }), - ), - ), - ], - ), - ); + TextSpan( + text: "后,再进行设备控制".tr, + style: TextStyle( + color: Colors.white, + fontSize: 30.rpx, + ), + ), + ], + ), + ), + ), + ), + + // 已登录但无设备提示 + if (isLoggedIn && !hasDevice) + Center( + child: InkWell( + onTap: () => Get.toNamed("/mHTDeviceTypePage"), + child: RichText( + text: TextSpan( + children: [ + TextSpan( + text: "请先".tr, + style: TextStyle( + color: Colors.white, + fontSize: 30.rpx, + ), + ), + WidgetSpan( + child: Stack( + children: [ + Text( + "绑定设备".tr, + style: TextStyle( + color: stringToColor("#84F5FF"), + fontSize: 30.rpx, + ), + ), + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Container( + height: 1, + color: stringToColor("#84F5FF"), + ), + ), + ], + ), + ), + TextSpan( + text: "后,再进行设备控制".tr, + style: TextStyle( + color: Colors.white, + fontSize: 30.rpx, + ), + ), + ], + ), + ), + ), + ), + + // 显示 WebView + if (showWeb) + Expanded( + child: Align( + alignment: Alignment.topLeft, + child: Obx(() { + return Stack( + children: [ + controller.ready.value + ? controller.web.build() + : Container(), + if (!controller.loadRecource.value) + Positioned.fill( + child: Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage( + 'assets/images/new_background.png'), + fit: BoxFit.fill, + ), + ), + alignment: Alignment.center, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + CircularProgressIndicator( + valueColor: + AlwaysStoppedAnimation( + Colors.white), + ), + ], + ), + ), + ), + ], + ); + }), + ), + ), + ], + ), + )); }); } }