273 lines
10 KiB
Dart
273 lines
10 KiB
Dart
import 'package:ef/ef.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'package:vbvs_app/common/color/appConstants.dart';
|
|
import 'package:vbvs_app/common/util/CommonVariables.dart';
|
|
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
|
import 'package:vbvs_app/common/util/FitTool.dart';
|
|
import 'package:vbvs_app/common/util/MyUtils.dart';
|
|
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
|
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
|
import 'package:vbvs_app/controller/user_info_controller.dart';
|
|
import 'package:vbvs_app/pages/common/selectDialog.dart';
|
|
import 'package:vbvs_app/pages/main_bottom/component/main_page_b_bottom_change.dart';
|
|
import 'package:vbvs_app/pages/mh_page/test/WebviewTestModel.dart';
|
|
|
|
class HomeDeviceStausWidget extends StatefulWidget {
|
|
final deviceStatus;
|
|
|
|
const HomeDeviceStausWidget({super.key, required this.deviceStatus});
|
|
|
|
@override
|
|
State<HomeDeviceStausWidget> createState() => _HomeDeviceStausWidgetState();
|
|
}
|
|
|
|
class _HomeDeviceStausWidgetState extends State<HomeDeviceStausWidget> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: double.infinity,
|
|
constraints: BoxConstraints(minHeight: 180.rpx),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xFF003058),
|
|
borderRadius: BorderRadius.circular(16.rpx),
|
|
),
|
|
child: Padding(
|
|
padding: EdgeInsetsDirectional.fromSTEB(67.rpx, 0.rpx, 30.rpx, 0.rpx),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Flexible(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: 170.rpx,
|
|
height: 81.rpx,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(8.rpx),
|
|
child: Image.network(
|
|
widget
|
|
.deviceStatus['device_image'], // 从DeviceStatus获取图片
|
|
width: 200.rpx,
|
|
height: 200.rpx,
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
'${(widget.deviceStatus['name'] ?? '').isEmpty ? '未命名'.tr : widget.deviceStatus['name']}',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 26.rpx,
|
|
letterSpacing: 0.0.rpx,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
].divide(SizedBox(height: 26.rpx)),
|
|
),
|
|
),
|
|
SizedBox(width: 26.rpx),
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
// Text(
|
|
// widget.deviceStatus['status'] == 1 ? '在线'.tr : '离线'.tr,
|
|
// style: TextStyle(
|
|
// color: widget.deviceStatus['status'] == 1
|
|
// ? stringToColor("#07BD60")
|
|
// : stringToColor("#F84B20"),
|
|
// fontSize: 26.rpx,
|
|
// letterSpacing: 0.0.rpx,
|
|
// ),
|
|
// ),
|
|
CustomCard(
|
|
gradientDirection: GradientDirection.vertical,
|
|
borderRadius: 10.rpx,
|
|
onTap: () async {
|
|
try {
|
|
var device = widget.deviceStatus;
|
|
|
|
WebviewTestController webviewTestController = Get.find();
|
|
webviewTestController.web.jsbridge?.dart.switchLanguage(
|
|
mhLanguageController
|
|
.selectLanguage.value!.language_code);
|
|
await checkBlueToothPermissin();
|
|
webviewTestController.web.jsbridge?.dart
|
|
.pageActive(false);
|
|
await Future.delayed(Duration(seconds: 1));
|
|
webviewTestController.web.jsbridge?.dart
|
|
.appToHtmlDevice(device);
|
|
MainPageBBottomChange.jumpTo(2);
|
|
} catch (e) {
|
|
DailyLogUtils.writeError("发生异常: $e");
|
|
}
|
|
},
|
|
colors:
|
|
AppConstants().mhtButtongradientColors, // 你原本没有渐变,单色即可
|
|
enableGradient: true, // 关闭渐变
|
|
enableAnimation: true, // 启用缩放动画
|
|
child: SizedBox(
|
|
width: 150.rpx,
|
|
height: 61.rpx,
|
|
child: Center(
|
|
child: Text(
|
|
'控制'.tr,
|
|
style: TextStyle(
|
|
color: Color(0xFF003058),
|
|
fontSize: 26.rpx,
|
|
letterSpacing: 0.0.rpx,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
].divide(SizedBox(height: 36.rpx)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// Future<Map> checkBlueToothPermissin() async {
|
|
// UserInfoController userInfoController = Get.find();
|
|
// bool show = false;
|
|
// Map data = {};
|
|
// var bluetoothScanGranted;
|
|
// var bluetoothConnectGranted;
|
|
// var locationGranted;
|
|
// try {
|
|
// // 如果没初始化过,就检查并请求权限
|
|
// if (userInfoController.initLocationpermission != 1) {
|
|
// bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
|
// bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
|
// locationGranted = await Permission.location.isGranted;
|
|
|
|
// // 如果权限没全部授予
|
|
// if (!bluetoothScanGranted ||
|
|
// !bluetoothConnectGranted ||
|
|
// !locationGranted) {
|
|
// show = true;
|
|
// // 同屏显示权限说明弹窗(阻塞等待用户点击确认)
|
|
// showPermissionInfoDialog(
|
|
// Get.context!,
|
|
// CommonVariables().bluetoothpermissionInfo,
|
|
// );
|
|
|
|
// // 再请求权限
|
|
// await [
|
|
// Permission.bluetoothScan,
|
|
// Permission.bluetoothConnect,
|
|
// Permission.location,
|
|
// ].request();
|
|
|
|
// // 再次检查最新权限状态
|
|
// bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
|
// bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
|
// locationGranted = await Permission.location.isGranted;
|
|
// }
|
|
// }
|
|
// // 通知 web 端
|
|
// data = {
|
|
// 'bluetoothScanGranted': bluetoothScanGranted,
|
|
// 'bluetoothConnectGranted': bluetoothConnectGranted,
|
|
// 'locationGranted': locationGranted,
|
|
// };
|
|
// WebviewTestController webviewTestController = Get.find();
|
|
// // webviewTestController.web.jsbridge?.dart.updatePermission(data);
|
|
// } catch (e) {
|
|
// ef.log("蓝牙权限:$e");
|
|
// } finally {
|
|
// if (show) {
|
|
// Navigator.of(Get.context!, rootNavigator: true).pop();
|
|
// }
|
|
// }
|
|
|
|
// // 标记初始化完成
|
|
// userInfoController.initLocationpermission = 1;
|
|
// return data;
|
|
// }
|
|
|
|
Future<Map> checkBlueToothPermissin() async {
|
|
UserInfoController userInfoController = Get.find();
|
|
bool show = false;
|
|
Map data = {};
|
|
var bluetoothScanGranted;
|
|
var bluetoothConnectGranted;
|
|
var locationGranted;
|
|
|
|
try {
|
|
// 先显示权限说明弹窗(同屏显示)
|
|
bool bluetoothScanPermanentlyDenied =
|
|
await Permission.bluetoothScan.isPermanentlyDenied;
|
|
bool bluetoothConnectPermanentlyDenied =
|
|
await Permission.bluetoothConnect.isPermanentlyDenied;
|
|
bool locationPermanentlyDenied =
|
|
await Permission.location.isPermanentlyDenied;
|
|
|
|
if (bluetoothScanPermanentlyDenied ||
|
|
bluetoothConnectPermanentlyDenied ||
|
|
locationPermanentlyDenied) {
|
|
return data; // 直接返回,不再弹窗申请
|
|
}
|
|
if (userInfoController.initLocationpermission == 1) {
|
|
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
|
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
|
locationGranted = await Permission.location.isGranted;
|
|
data = {
|
|
'bluetoothScanGranted': bluetoothScanGranted,
|
|
'bluetoothConnectGranted': bluetoothConnectGranted,
|
|
'locationGranted': locationGranted,
|
|
};
|
|
return data;
|
|
}
|
|
showPermissionInfoDialog(
|
|
Get.context!,
|
|
CommonVariables().bluetoothpermissionInfo,
|
|
);
|
|
show = true;
|
|
|
|
// 检查并请求权限
|
|
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
|
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
|
locationGranted = await Permission.location.isGranted;
|
|
|
|
if (!bluetoothScanGranted || !bluetoothConnectGranted || !locationGranted) {
|
|
await [
|
|
Permission.bluetoothScan,
|
|
Permission.bluetoothConnect,
|
|
Permission.location,
|
|
].request();
|
|
|
|
// 更新权限状态
|
|
bluetoothScanGranted = await Permission.bluetoothScan.isGranted;
|
|
bluetoothConnectGranted = await Permission.bluetoothConnect.isGranted;
|
|
locationGranted = await Permission.location.isGranted;
|
|
}
|
|
|
|
data = {
|
|
'bluetoothScanGranted': bluetoothScanGranted,
|
|
'bluetoothConnectGranted': bluetoothConnectGranted,
|
|
'locationGranted': locationGranted,
|
|
};
|
|
|
|
// 通知 web 端
|
|
WebviewTestController webviewTestController = Get.find();
|
|
// webviewTestController.web.jsbridge?.dart.updatePermission(data);
|
|
} catch (e) {
|
|
ef.log("蓝牙权限:$e");
|
|
} finally {
|
|
if (show) {
|
|
Navigator.of(Get.context!, rootNavigator: true).pop();
|
|
}
|
|
}
|
|
|
|
userInfoController.initLocationpermission = 1;
|
|
return data;
|
|
}
|