Files
tuiche/lib/pages/mh_page/device/device.dart
wyf 6423485e34 1.更新睡眠报告无数据时居中显示
2.更新控制按钮变圆圈
3.修复首页设备列表名称太长导致控制图标挤出去
2025-07-15 14:18:16 +08:00

480 lines
24 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/color/appFontsize.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/TopSlideNotification.dart';
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
import 'package:vbvs_app/controller/mh_controller/device_list_controller.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 DeviceInfoWidget extends GetView {
int index;
DeviceListController deviceListController;
DeviceInfoWidget({required this.index, required this.deviceListController}) {}
@override
Widget build(BuildContext context) {
var device = deviceListController.model.deviceList[index];
GlobalController globalController = Get.find();
return Padding(
padding: EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 0),
child: Container(
// width: MediaQuery.sizeOf(context).width,
height: 381.rpx,
// constraints: BoxConstraints(
// minHeight: 140,
// ),
decoration: BoxDecoration(
color: Color(0xFF003058),
borderRadius: BorderRadius.circular(16.rpx),
),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(26.rpx, 33.rpx, 26.rpx, 0),
child: Container(
// width: MediaQuery.sizeOf(context).width,
height: 381.rpx,
// constraints: BoxConstraints(
// minHeight: 106,
// ),
child: Container(
// width: MediaQuery.sizeOf(context).width,
height: 381.rpx,
constraints: BoxConstraints(
minHeight: 130,
),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
deviceListController.model.deviceList[index]['name'] ??
getNameByType(
deviceListController.model.deviceList[index]),
style: TextStyle(
fontFamily: 'Readex Pro',
color: Colors.white,
fontSize: 30.rpx,
letterSpacing: 0,
),
maxLines: 1, // 限制显示一行
overflow: TextOverflow.ellipsis, // 超出部分显示省略号
),
Container(
margin: EdgeInsets.only(top: 36.rpx),
width: MediaQuery.sizeOf(context).width,
// height: MediaQuery.sizeOf(context).height * 0.065,
constraints: BoxConstraints(
minHeight: 55,
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: InkWell(
onTap: () async {
// GlobalController globalController = Get.find();
// var tmp = globalController.model.deviceMain;
// BedController bedController = Get.find();
// bedController.websocketSend(2);
// globalController.model.deviceMain = device;
// globalController.updateAll();
// bedController.websocketSend(1);
// var result = await Get.toNamed("/bodyChart");
// bedController.websocketSend(2);
// globalController.model.deviceMain = tmp;
},
child: Container(
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildInfoRow(
'设备ID',
deviceListController
.model.deviceList[index]["_id"] ??
'',
valueColor: (deviceListController
.model.deviceList[index]
["status"]?["status"]) ==
1
? Color(0xFF929699)
: null),
_buildInfoRow(
'房间',
deviceListController.model
.deviceList[index]["roomName"] ??
'',
valueColor: (deviceListController
.model.deviceList[index]
["status"]?["status"]) ==
1
? Color(0xFF929699)
: null),
_buildInfoRow(
'设备状态',
(deviceListController
.model.deviceList[index]
["status"]?["status"]) ==
1
? '已绑定'
: '已绑定',
valueColor: (deviceListController
.model.deviceList[index]
["status"]?["status"]) ==
1
? Color(0xFF6BFDAC)
: Color(0xFF6BFDAC)),
// Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// Expanded(
// child: RichText(
// text: TextSpan(
// children: [
// TextSpan(
// text: '设备ID' +
// (deviceListController.model
// .deviceList[
// index]['_id'] ??
// ''),
// style: TextStyle(
// fontFamily: 'Readex Pro',
// color: Color(0xFFC8CBD2),
// fontSize: 26.rpx,
// letterSpacing: 0,
// height: 1),
// ),
// ],
// ),
// maxLines: 1, // 限制显示一行
// overflow: TextOverflow
// .ellipsis, // 超出部分显示省略号
// ),
// ),
// ],
// ),
// Align(
// alignment: AlignmentDirectional(-1, 0),
// child: Text(
// '房间:' +
// (deviceListController
// .model.deviceList[index]
// ['roomName'] ??
// ''),
// style: TextStyle(
// fontFamily: 'Readex Pro',
// color: Color(0xFFC8CBD2),
// fontSize: 26.rpx,
// letterSpacing: 0,
// height: 1),
// ),
// ),
// Align(
// alignment: AlignmentDirectional(-1, 0),
// child: Text(
// '设备状态:${(deviceListController.model.deviceList[index]["status"]?["status"]) == 1 ? '在线' : '离线'}',
// style: TextStyle(
// fontFamily: 'Readex Pro',
// color: Color(0xFFC8CBD2),
// fontSize: 26.rpx,
// letterSpacing: 0,
// height: 1),
// ),
// )
].divide(SizedBox(height: 36.rpx)),
),
),
),
),
Align(
alignment: AlignmentDirectional(0, 0),
child: Container(
width: 150.rpx,
height: 90.rpx,
child: FFButtonWidget(
onPressed: () async {
try {
WebviewTestController webviewTestController =
Get.find();
webviewTestController.web.jsbridge?.dart
.pageActive(false);
// await Future.delayed(Duration(seconds: 1));
webviewTestController.web.jsbridge?.dart
.appToHtmlDevice(device);
MainPageBBottomChange.jumpTo(2);
Get.until((route) =>
Get.currentRoute ==
"/mianPageBottomChange");
} catch (e) {
DailyLogUtils.writeError("发生异常: $e");
}
},
text: '控制',
options: FFButtonOptions(
color: Color(0XFF85F5FF),
textStyle: TextStyle(
fontFamily: 'Readex Pro',
color: Color(0xFF011D33),
fontSize: 28.rpx,
letterSpacing: 0,
),
elevation: 0,
borderSide: BorderSide(
color: Colors.transparent,
width: 1,
),
borderRadius: BorderRadius.circular(16.rpx),
),
),
),
),
],
),
),
Padding(
padding: EdgeInsetsDirectional.fromSTEB(0, 36.rpx, 0, 0),
child: Container(
width: MediaQuery.sizeOf(context).width,
height: 0.5.rpx,
decoration: BoxDecoration(
color: Color(0xFF929699),
),
),
),
Flexible(
child: Container(
margin: EdgeInsets.only(right: 26.rpx),
width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height * 1,
constraints: BoxConstraints(
minHeight: 60,
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
InkWell(
onTap: () async {
await Get.toNamed("/deviceSharePage",
arguments: deviceListController
.model.deviceList[index]);
// if (device['type'] == 1) {
// globalController.model.deviceMain = device;
// await Get.toNamed("/deviceSharePage");
// globalController.getDeviceList();
// }
},
child: Container(
height: MediaQuery.sizeOf(context).height * 0.1,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Align(
alignment: AlignmentDirectional(1, 0),
child: Container(
width: 42.rpx,
height: 42.rpx,
child: SvgPicture.asset(
'assets/images/group.svg',
color: Color(0xFF85F5FF),
),
)),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
children: [
if (device['bind_type'] == 1)
Text(
'已分享:',
style: TextStyle(
fontFamily: 'Readex Pro',
fontSize:
AppFontsize.normal_text_size,
letterSpacing: 0,
color: Colors.white,
),
),
if (device['bind_type'] == 1)
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(
5, 0, 5, 0),
child: Text(
(deviceListController.model
.deviceList[index]
['shareNum'] ??
0)
.toString(),
style: TextStyle(
fontFamily: 'Readex Pro',
color: Color(0xFF85F5FF),
fontSize:
AppFontsize.normal_text_size,
letterSpacing: 0,
),
),
),
if (device['bind_type'] == 1)
Text(
'',
style: TextStyle(
fontFamily: 'Readex Pro',
fontSize:
AppFontsize.normal_text_size,
letterSpacing: 0,
color: Colors.white,
),
),
if (device['bind_type'] == 2)
Text(
'来自',
style: TextStyle(
fontFamily: 'Readex Pro',
fontSize:
AppFontsize.normal_text_size,
letterSpacing: 0,
color: Colors.white,
),
),
if (device['bind_type'] == 2)
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(
5, 0, 5, 0),
child: Text(
'${device['source']?.length > 5 ? device['source'].substring(0, 5) + '...' : device['source']}',
style: TextStyle(
fontFamily: 'Readex Pro',
color: Color(0xFF85F5FF),
fontSize:
AppFontsize.normal_text_size,
letterSpacing: 0,
),
),
),
if (device['bind_type'] == 2)
Text(
'的分享',
style: TextStyle(
fontFamily: 'Readex Pro',
fontSize: 21.rpx,
letterSpacing: 0,
color: Colors.white,
),
),
],
),
].divide(SizedBox(width: 6)),
),
),
),
InkWell(
onTap: () {
// TopSlideNotification.show(
// context,
// text: "功能开发中...",
// );
// var a = [device["bindMacA"]];
// if ("${device["bindMacB"]}".length > 6) {
// a.add(device["bindMacB"]);
// }
// Get.toNamed("/sleepWebview", arguments: a);
Get.toNamed("/mhtSleepReportReturnPage",
arguments: device);
},
child: Container(
height: MediaQuery.sizeOf(context).height * 0.1,
constraints: BoxConstraints(
minHeight: 25,
),
alignment: Alignment.center,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Align(
alignment: AlignmentDirectional(0, 0),
child: SvgPicture.asset(
"assets/images/table.svg",
width: 24.rpx,
height: 24.rpx,
color: Color(0xFF85F5FF),
),
),
SizedBox(width: 5),
Text(
'睡眠报告',
style: TextStyle(
fontFamily: 'Readex Pro',
color: Colors.white,
fontSize: 21.rpx,
letterSpacing: 0,
),
),
],
),
),
),
],
),
),
),
],
),
),
),
),
),
);
}
Widget _buildInfoRow(String label, String value, {Color? valueColor}) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'$label ',
style:
TextStyle(color: Color(0XFF929699), fontSize: 26.rpx, height: 1),
),
Flexible(
child: Text(
value,
style: TextStyle(
color: valueColor ?? Colors.white, fontSize: 26.rpx, height: 1),
overflow: TextOverflow.ellipsis,
),
),
],
);
}
getNameByType(device) {
if (device['device_type'] == null) {
return '未知类型设备'.tr;
}
if (device['device_type'] == 2) {
return 'SWES 智能床'.tr;
}
if (device['device_type'] == 3) {
return 'SWES 智能床垫'.tr;
}
}
}