更新本地加载

This commit is contained in:
wyf
2025-07-07 14:09:23 +08:00
parent 58b2bebe93
commit b59fd0a2f6
7 changed files with 496 additions and 98 deletions

View File

@@ -0,0 +1,305 @@
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/pages/mh_page/homepage/controller/mht_home_controller.dart';
import 'package:vbvs_app/pages/sleep_report/new_sleep_report_page.dart';
class MhtSleepReportReturnPage extends StatefulWidget {
final dynamic data;
const MhtSleepReportReturnPage({super.key, required this.data});
@override
State<MhtSleepReportReturnPage> createState() =>
_MhtSleepReportReturnPageState();
}
class _MhtSleepReportReturnPageState extends State<MhtSleepReportReturnPage> {
final UserInfoController userInfoController = Get.find();
final MHTHomeController deviceController = Get.find();
final MHTHomeController homeController = Get.find();
final double borderRadius = 16.rpx;
final formFieldController = FormFieldController<String>(null);
final personInfo = {}.obs;
@override
void initState() {
super.initState();
if (userInfoController.model.login == 1) {
// 设备列表
deviceController.getDeviceList(group: 'room');
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/new_background.png'),
fit: BoxFit.fill,
),
),
child: Scaffold(
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
iconTheme: IconThemeData(color: themeController.currentColor.sc3),
titleSpacing: 0,
title: Container(
width: double.infinity,
height: 180.rpx,
child: Stack(
alignment: Alignment.center,
children: [
/// 下拉选人
Positioned(
right: 20.rpx,
child: ScrollbarTheme(
data: ScrollbarThemeData(
thumbColor:
MaterialStateProperty.all(Colors.transparent),
trackColor:
MaterialStateProperty.all(Colors.transparent),
trackBorderColor:
MaterialStateProperty.all(Colors.transparent),
),
child: ValueListenableBuilder(
valueListenable: formFieldController,
// builder: (context, val, _) {
// return ClipRRect(
// borderRadius: BorderRadius.circular(36.rpx),
// child: Theme(
// data: Theme.of(context).copyWith(
// splashColor: Colors.transparent,
// highlightColor: Colors.transparent,
// hoverColor: Colors.transparent,
// ),
// child: FlutterFlowDropDown<String>(
// controller: formFieldController,
// options: deviceController.personnelList.value
// .map<String>((d) => "${d["mac"]}")
// .toList(),
// optionLabels: deviceController
// .personnelList.value
// .map<String>((d) => d["name"] ?? d["mac"])
// .toList(),
// onChanged: (val) {
// WidgetsBinding.instance
// .addPostFrameCallback((_) {
// final list =
// deviceController.personnelList.value;
// final selectedPerson = list.firstWhere(
// (element) => element['mac'] == val,
// orElse: () => null,
// );
// homeController.selectPerson.value =
// selectedPerson;
// personInfo.value = selectedPerson;
// homeController.selectedDayIndex =
// 6.obs; // 默认选第7天
// if (val == null) {
// homeController.sleepDays.value = [];
// } else {
// homeController.selectDevcie.value = val;
// deviceController.getSleeps(val);
// homeController.updateAll();
// }
// });
// },
// width: 300.rpx,
// height: 81.rpx,
// maxHeight: 300.rpx,
// textStyle: TextStyle(
// fontSize: 28.rpx,
// overflow: TextOverflow.ellipsis,
// color: Colors.white,
// ),
// hintText: '',
// icon: Icon(
// Icons.keyboard_arrow_down_rounded,
// color: stringToColor("#FFFFFF"),
// size: 30.rpx,
// ),
// fillColor: stringToColor("#011D33"),
// elevation: 2,
// borderColor: Colors.transparent,
// borderWidth: 2,
// borderRadius: 0.rpx,
// margin: EdgeInsetsDirectional.fromSTEB(
// 32.rpx, 8.rpx, 32.rpx, 8.rpx),
// hidesUnderline: true,
// isOverButton: false,
// isSearchable: false,
// isMultiSelect: false,
// ),
// ),
// );
// },
builder: (context, val, _) {
// 只保留符合 bind_mac_a/b 的人员
final macA = widget.data['bind_mac_a'];
final macB = widget.data['bind_mac_b'];
final list = deviceController.personnelList.value;
final filteredList = list
.where(
(p) => p['mac'] == macA || p['mac'] == macB)
.toList();
// 默认只赋值一次
if (formFieldController.value == null &&
filteredList.isNotEmpty) {
final defaultMac = filteredList.first['mac'];
WidgetsBinding.instance.addPostFrameCallback((_) {
formFieldController.value = defaultMac;
final selectedPerson = filteredList.firstWhere(
(element) => element['mac'] == defaultMac,
orElse: () => null,
);
homeController.selectPerson.value =
selectedPerson;
personInfo.value = selectedPerson;
homeController.selectedDayIndex = 6.obs;
homeController.selectDevcie.value = defaultMac;
deviceController.getSleeps(defaultMac);
homeController.updateAll();
});
}
return ClipRRect(
borderRadius: BorderRadius.circular(36.rpx),
child: Theme(
data: Theme.of(context).copyWith(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
),
child: FlutterFlowDropDown<String>(
controller: formFieldController,
options: filteredList
.map<String>((d) => "${d["mac"]}")
.toList(),
optionLabels: filteredList
.map<String>((d) => d["name"] ?? d["mac"])
.toList(),
onChanged: (val) {
WidgetsBinding.instance
.addPostFrameCallback((_) {
final selectedPerson =
filteredList.firstWhere(
(element) => element['mac'] == val,
orElse: () => null,
);
homeController.selectPerson.value =
selectedPerson;
personInfo.value = selectedPerson;
homeController.selectedDayIndex = 6.obs;
if (val == null) {
homeController.sleepDays.value = [];
} else {
homeController.selectDevcie.value = val;
deviceController.getSleeps(val);
homeController.updateAll();
}
});
},
width: 300.rpx,
height: 81.rpx,
maxHeight: 300.rpx,
textStyle: TextStyle(
fontSize: 28.rpx,
overflow: TextOverflow.ellipsis,
color: Colors.white,
),
hintText: '',
icon: Icon(
Icons.keyboard_arrow_down_rounded,
color: stringToColor("#FFFFFF"),
size: 30.rpx,
),
fillColor: stringToColor("#003058"),
elevation: 2,
borderColor: Colors.transparent,
borderWidth: 2,
borderRadius: 0.rpx,
margin: EdgeInsetsDirectional.fromSTEB(
32.rpx, 8.rpx, 32.rpx, 8.rpx),
hidesUnderline: true,
isOverButton: false,
isSearchable: false,
isMultiSelect: false,
),
),
);
},
),
),
),
/// 左侧返回 + 标题
Positioned(
left: 0,
child: Row(
children: [
returnIconButtomNew,
Text(
'健康报告'.tr,
style: TextStyle(
fontFamily: 'Readex Pro',
color: themeController.currentColor.sc3,
letterSpacing: 0,
fontSize: 30.rpx,
),
),
],
),
),
],
),
),
),
body: SafeArea(
child: Obx(() {
final device = homeController.selectDevcie.value;
if (device != null && device.isNotEmpty) {
return Column(
children: [
Expanded(
child: NewSleepReportPage(
data: {
"tag": "444",
'date': DateTime.now().millisecondsSinceEpoch,
'mac': device,
'person': homeController.selectPerson.value,
'backgroundImg': 'assets/images/new_background.png',
'arrow': false,
'noBackImg': true,
'person_show': false,
},
),
),
],
);
}
return Center(
child: Text('暂无数据', style: TextStyle(color: Colors.white)));
}),
),
),
),
);
}
}