更新界面布局

This commit is contained in:
wyf
2025-06-16 21:08:54 +08:00
parent acde8340a8
commit aa51d92d2b
19 changed files with 2595 additions and 1524 deletions

View File

@@ -28,36 +28,20 @@ class _NewHomePageState extends State<NewHomePage> {
double borderRadius = 16.rpx;
var formFieldController = FormFieldController<String>(null);
var personInfo = {}.obs;
GlobalController gloablController = Get.find();
WeatherModelController weatherModelController = Get.find();
var sleepDays = [].obs;
var sleep_mac = "".obs;
Map scoreColor = {
"-1": "#d3d3d3",
"1": "#4e8408",
"2": "#7bbb33",
"3": "#e15b8d",
"4": "#ff0000",
};
Map scoreName = {
"-1": "暂无",
"1": "优秀",
"2": "良好",
"3": "合格",
"4": "注意",
};
var selectedDayIndex = (6).obs;
@override
void initState() {
super.initState();
if (userInfoController.model.login == 1) {
//查询人员信息列表
deviceController.getPersonList();
//请求绑定设备列表
homeController.getSleepReport();
// homeController.getSleepReport();
deviceController.getDeviceNum().then((apiResponse) {
if (apiResponse.code != HttpStatusCodes.ok) {
TopSlideNotification.show(
@@ -76,10 +60,15 @@ class _NewHomePageState extends State<NewHomePage> {
);
} else {
//请求睡眠报告
deviceController.getSleepReport();
// deviceController.getSleepReport();
}
});
}
WidgetsBinding.instance.addPostFrameCallback((_) {
if (homeController.sleepDays.value.isNotEmpty) {
selectedDayIndex.value = homeController.sleepDays.value.length - 1;
}
});
}
getWeekName(int i) {
@@ -121,7 +110,7 @@ class _NewHomePageState extends State<NewHomePage> {
);
} else {
//请求睡眠报告
deviceController.getSleepReport();
// deviceController.getSleepReport();
}
});
int login = userInfoController.model.login!;
@@ -242,502 +231,6 @@ class _NewHomePageState extends State<NewHomePage> {
),
),
),
// Obx(() {
// return Container(
// padding: EdgeInsets.only(left: 30.rpx, right: 30.rpx),
// child: Column(
// children: [
// if (gloablController.model.deviceList.length > 0)
// Container(
// child: Column(
// children: [
// Container(
// width: MediaQuery.sizeOf(context).width,
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(
// borderRadius),
// ),
// child: Column(
// mainAxisSize: MainAxisSize.max,
// children: [
// Padding(
// padding: EdgeInsetsDirectional
// .fromSTEB(30.rpx, 16.rpx,
// 16.rpx, 8.rpx),
// child: Container(
// width:
// MediaQuery.sizeOf(context)
// .width,
// height:
// MediaQuery.sizeOf(context)
// .height *
// 0.065,
// decoration: BoxDecoration(
// color: FlutterFlowTheme.of(
// context)
// .secondaryBackground,
// ),
// child: Row(
// mainAxisSize:
// MainAxisSize.max,
// mainAxisAlignment:
// MainAxisAlignment
// .spaceBetween,
// children: [
// ValueListenableBuilder(
// valueListenable:
// formFieldController,
// builder: (c, a, s) =>
// FlutterFlowDropDown<
// String>(
// controller:
// formFieldController,
// options: gloablController
// .model.JunheDevices
// .map<String>((d) =>
// "${d["mac"]}")
// .toList(),
// optionLabels:
// gloablController
// .model
// .JunheDevices
// .map<String>(
// (d) {
// var s = d["name"] ??
// d["mac"];
// if (s == null) {
// return "";
// } else {
// return "$s";
// }
// }).toList(),
// onChanged: (val) {
// // print("$val");
// // if (val == null) {
// // sleepDays.value = [];
// // } else {
// // getSleeps(
// // formFieldController
// // .value);
// // }
// // // sleep_mac.value = val!;
// },
// width: 360.rpx,
// height: 72.rpx,
// maxHeight: 200.rpx,
// textStyle: TextStyle(
// fontSize: 28.rpx,
// overflow:
// TextOverflow
// .ellipsis),
// hintText: '',
// icon: Icon(
// Icons
// .keyboard_arrow_down_rounded,
// color: FlutterFlowTheme
// .of(context)
// .secondaryText,
// size: 48.rpx,
// ),
// fillColor:
// stringToColor(
// "#F3F5F6"),
// elevation: 2,
// borderColor:
// stringToColor(
// "#F3F5F6"),
// borderWidth: 2,
// borderRadius: 18,
// margin:
// EdgeInsetsDirectional
// .fromSTEB(
// 32.rpx,
// 8.rpx,
// 32.rpx,
// 8.rpx),
// hidesUnderline: true,
// isOverButton: false,
// isSearchable: false,
// isMultiSelect: false,
// ),
// ),
// InkWell(
// onTap: () {
// // if (formFieldController
// // .value !=
// // null) {
// // Get.toNamed(
// // "/sleepWebview",
// // arguments: [
// // formFieldController
// // .value
// // ]);
// // }
// },
// child: Row(
// mainAxisSize:
// MainAxisSize.max,
// children: [
// Text(
// '睡眠报告',
// style: FlutterFlowTheme
// .of(context)
// .bodyMedium
// .override(
// fontFamily:
// 'Readex Pro',
// letterSpacing:
// 0,
// fontSize:
// 30.rpx),
// ),
// SizedBox(
// width: 12.rpx,
// ),
// SvgPicture.asset(
// "assets/images/table.svg",
// width: 28.rpx,
// height: 28.rpx),
// SizedBox(
// width: 20.rpx,
// ),
// ],
// ),
// ),
// ],
// ),
// ),
// ),
// Container(
// padding: EdgeInsets.only(
// top: 0.rpx,
// bottom: 20.rpx,
// left: 16.rpx,
// right: 16.rpx),
// width: double.infinity,
// decoration: BoxDecoration(),
// child: Row(
// mainAxisSize: MainAxisSize.max,
// crossAxisAlignment:
// CrossAxisAlignment.start,
// children: [
// ...List.generate(
// sleepDays.value.length,
// (index) {
// var day = sleepDays[index];
// return Expanded(
// child: Container(
// padding:
// EdgeInsets.only(
// top: 10.rpx,
// bottom: 20.rpx),
// width: 100,
// // decoration: BoxDecoration(
// // color: index == 2
// // ? stringToColor("#F3F5F6")
// // : Colors.white,
// // borderRadius:
// // BorderRadius.circular(
// // borderRadius),
// // ),
// child: Column(
// mainAxisSize:
// MainAxisSize.max,
// mainAxisAlignment:
// MainAxisAlignment
// .start,
// crossAxisAlignment:
// CrossAxisAlignment
// .center,
// children: [
// Text(
// day['week'],
// style: FlutterFlowTheme
// .of(context)
// .bodyMedium
// .override(
// fontFamily:
// 'Readex Pro',
// fontSize:
// 30.rpx,
// letterSpacing:
// 0,
// ),
// ),
// Text(
// day['date'],
// style: FlutterFlowTheme
// .of(context)
// .bodyMedium
// .override(
// fontFamily:
// 'Readex Pro',
// letterSpacing:
// 0,
// fontSize:
// 24.rpx,
// ),
// ),
// SizedBox(
// height: 6.rpx,
// ),
// Column(
// children: [
// Row(
// mainAxisSize:
// MainAxisSize
// .max,
// mainAxisAlignment:
// MainAxisAlignment
// .center,
// children: [
// Text(
// '${day['score'] ?? "-"}',
// style: FlutterFlowTheme.of(
// context)
// .bodyMedium
// .override(
// fontFamily:
// 'Readex Pro',
// fontSize:
// 48.rpx,
// letterSpacing:
// 0,
// ),
// ),
// if (day['score'] !=
// null)
// SizedBox(
// width: 2
// .rpx,
// ),
// if (day['score'] !=
// null)
// Text(
// '分',
// style: FlutterFlowTheme.of(context)
// .bodyMedium
// .override(
// fontFamily: 'Readex Pro',
// letterSpacing: 0,
// fontSize: 26.rpx,
// ),
// ),
// ],
// ),
// Container(
// width:
// 120.rpx,
// height:
// 52.rpx,
// decoration:
// BoxDecoration(
// color: stringToColor(
// day['scoreColor'] ??
// "#f3f5f6"),
// borderRadius:
// BorderRadius.circular(
// 26.rpx),
// shape: BoxShape
// .rectangle,
// ),
// alignment:
// Alignment
// .center,
// child: Text(
// '${day['scoreType'] ?? "暂无"}',
// style: FlutterFlowTheme.of(
// context)
// .bodyMedium
// .override(
// fontFamily:
// 'Readex Pro',
// color: day['scoreType'] != null
// ? Colors.white
// : stringToColor("#ced1d7"),
// letterSpacing:
// 0,
// fontSize:
// 28.rpx,
// ),
// ),
// )
// ],
// )
// ],
// ),
// ),
// );
// })
// ],
// ),
// ),
// ],
// ),
// ),
// ...List.generate(
// gloablController.model.deviceList
// .length, (index) {
// var device = gloablController
// .model.deviceList[index];
// String rname = device['roomName'];
// if (index != 0) {
// String lrname = gloablController
// .model.deviceList[index - 1]
// ["roomName"];
// if (lrname == rname) {
// rname = "";
// }
// }
// return Column(children: [
// Padding(
// padding:
// EdgeInsetsDirectional.fromSTEB(
// 20.rpx, 20.rpx, 0, 0),
// child: Container(
// decoration: BoxDecoration(),
// alignment:
// AlignmentDirectional(-1, 0),
// child: rname.isNotEmpty
// ? Text(
// "$rname",
// style: FlutterFlowTheme
// .of(context)
// .bodyMedium
// .override(
// fontFamily:
// 'Readex Pro',
// color: Colors.white,
// fontSize: 32.rpx,
// letterSpacing: 0,
// ),
// )
// : SizedBox(
// height: 10.rpx,
// ),
// ),
// ),
// // getDeviceList(context, device)
// ]);
// }),
// Padding(
// padding: EdgeInsetsDirectional.fromSTEB(
// 0, 40.rpx, 0, 100.rpx),
// child: Container(
// width:
// MediaQuery.sizeOf(context).width,
// height: 84.rpx,
// decoration: BoxDecoration(),
// child: FFButtonWidget(
// onPressed: () {
// // print('Button pressed ...');
// // Get.toNamed("/homeDeviceType");
// },
// text: '添加新设备'.tr,
// icon: Icon(
// Icons.add,
// size: 60.rpx,
// ),
// options: FFButtonOptions(
// height: 80.rpx,
// padding: EdgeInsetsDirectional
// .fromSTEB(
// 48.rpx, 0, 48.rpx, 0),
// iconPadding: EdgeInsetsDirectional
// .fromSTEB(0, 0, 0, 0),
// color: stringToColor("#182B7C"),
// textStyle:
// FlutterFlowTheme.of(context)
// .titleSmall
// .override(
// fontFamily:
// 'Readex Pro',
// color: Colors.white,
// letterSpacing: 0,
// fontSize: 30.rpx),
// elevation: 3,
// borderSide: BorderSide(
// color: Colors.transparent,
// width: 1,
// ),
// borderRadius:
// BorderRadius.circular(
// borderRadius),
// ),
// ),
// ),
// ),
// ],
// ),
// ),
// if (gloablController.model.deviceList.length == 0)
// Padding(
// padding: EdgeInsetsDirectional.fromSTEB(
// 0, 0, 0, 80.rpx),
// child: ClickableContainer(
// backgroundColor: Colors.transparent,
// highlightColor: Colors.transparent,
// padding: EdgeInsets.all(0),
// onTap: () {
// if (userInfoController.model.login ==
// null ||
// userInfoController.model.login == 0) {
// TopSlideNotification.show(context,
// text: "请先登录".tr,
// textColor: themeController
// .currentColor.sc9);
// Get.toNamed("/loginPage");
// } else {
// Get.toNamed("/mHTDeviceTypePage");
// }
// },
// child: Container(
// width: MediaQuery.sizeOf(context).width,
// height: 302.rpx,
// padding: EdgeInsets.only(
// top: 90.rpx, bottom: 80.rpx),
// decoration: BoxDecoration(
// borderRadius:
// BorderRadius.circular(borderRadius),
// border: Border.all(
// color:
// stringToColor("#85F5FF"), // 边框颜色
// width: 1.rpx, // 边框宽度
// ),
// ),
// child: Column(
// mainAxisSize: MainAxisSize.max,
// mainAxisAlignment:
// MainAxisAlignment.center,
// children: [
// SvgPicture.asset(
// 'assets/images/icon/add.svg',
// width: 42.rpx,
// height: 42.rpx,
// ),
// SizedBox(
// height: 32.rpx,
// ),
// Text(
// '添加一台新设备'.tr,
// style: TextStyle(
// color: stringToColor("#85F5FF"),
// fontSize: AppConstants()
// .normal_text_fontSize,
// letterSpacing: 0,
// ),
// ),
// ],
// ),
// ),
// ),
// ),
// ],
// ),
// );
// }),
//未登录
Obx(() {
if (userInfoController.model.login! == null ||
@@ -807,9 +300,343 @@ class _NewHomePageState extends State<NewHomePage> {
Obx(() {
if (userInfoController.model.login! != null &&
userInfoController.model.login! == 1) {
final list = deviceController.personnelList.value;
// 当数据第一次到达时自动赋值
if (list.isNotEmpty &&
formFieldController.value == null) {
formFieldController.value = list[0]["mac"];
personInfo.value = list[0];
deviceController
.getSleeps(formFieldController.value);
}
return SingleChildScrollView(
child: Column(
children: [
if (homeController.personnelList.value.length !=
0)
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
30.rpx, 40.rpx, 30.rpx, 10.rpx),
child: Container(
width: MediaQuery.sizeOf(context).width,
height:
MediaQuery.sizeOf(context).height *
0.184,
constraints: BoxConstraints(
minHeight: 350.rpx,
),
decoration: BoxDecoration(
color: stringToColor("#003058"),
borderRadius:
BorderRadius.circular(20.rpx),
),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(
30.rpx,
16.rpx,
16.rpx,
25.rpx),
child: Container(
width: MediaQuery.sizeOf(context)
.width,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
ScrollbarTheme(
data: ScrollbarThemeData(
thumbColor:
MaterialStateProperty
.all(Colors
.transparent),
trackColor:
MaterialStateProperty
.all(Colors
.transparent),
trackBorderColor:
MaterialStateProperty
.all(Colors
.transparent),
),
child:
ValueListenableBuilder(
valueListenable:
formFieldController,
builder: (c, a, s) =>
FlutterFlowDropDown<
String>(
controller:
formFieldController,
options: deviceController
.personnelList.value
.map<String>((d) =>
"${d["mac"]}")
.toList(),
optionLabels:
deviceController
.personnelList
.value
.map<String>(
(d) {
var s = d["name"] ??
d["mac"];
if (s == null) {
return "";
} else {
return "$s";
}
}).toList(),
onChanged: (val) {
final list =
deviceController
.personnelList
.value;
final selectedPerson =
list.firstWhere(
(element) =>
element[
'mac'] ==
val,
orElse: () =>
null, // 防止找不到时报错
);
personInfo.value =
selectedPerson;
selectedDayIndex =
(6).obs;
print("$val");
if (val == null) {
homeController
.sleepDays
.value = [];
} else {
deviceController
.getSleeps(
formFieldController
.value);
}
},
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(
"#184468"),
elevation: 2,
borderColor:
Colors.transparent,
borderWidth: 2,
borderRadius: 18,
margin:
EdgeInsetsDirectional
.fromSTEB(
32.rpx,
8.rpx,
32.rpx,
8.rpx),
hidesUnderline: true,
isOverButton: false,
isSearchable: false,
isMultiSelect: false,
),
),
),
InkWell(
onTap: () {
if (formFieldController
.value !=
null) {
Get.toNamed(
"/sleepWebview",
arguments: [
formFieldController
.value
]);
}
},
child: Row(
mainAxisSize:
MainAxisSize.max,
children: [
SizedBox(
width: 12.rpx,
),
SvgPicture.asset(
"assets/images/table.svg",
width: 28.rpx,
height: 28.rpx,
color: stringToColor(
"#FFFFFF"),
),
SizedBox(
width: 20.rpx,
),
],
),
),
],
),
),
),
Container(
padding: EdgeInsets.only(
top: 0.rpx,
bottom: 20.rpx,
left: 16.rpx,
right: 16.rpx,
),
width: double.infinity,
decoration: BoxDecoration(),
child: Obx(() => Row(
mainAxisSize:
MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
...List.generate(
homeController
.sleepDays
.value
.length, (index) {
var day = homeController
.sleepDays[index];
bool isSelected =
selectedDayIndex
.value ==
index;
return Expanded(
child: GestureDetector(
onTap: () {
selectedDayIndex
.value = index;
int? timeMillis =
parseToInt(day[
'time']); // 使用我们刚才封装的安全转换函数
Get.toNamed(
"/newSleepReportPage",
arguments: {
'date':
timeMillis,
'mac':
formFieldController
.value!,
'type': 1,
"person":
personInfo
.value,
'backgroundImg':
'assets/images/new_background.png',
// 'backgroundColor':stringToColor("#003058"),
},
);
},
child: Container(
padding:
EdgeInsets.only(
top: 10.rpx,
bottom: 20.rpx,
),
width: 90.rpx,
decoration:
BoxDecoration(
color: isSelected
? stringToColor(
"#184468")
: Colors
.transparent,
borderRadius:
BorderRadius
.circular(
8.rpx),
),
child: Column(
mainAxisSize:
MainAxisSize
.max,
mainAxisAlignment:
MainAxisAlignment
.start,
crossAxisAlignment:
CrossAxisAlignment
.center,
children: [
Text(
day['week'],
style: FlutterFlowTheme.of(
context)
.bodyMedium
.override(
fontFamily:
'Readex Pro',
fontSize:
30.rpx,
letterSpacing:
0,
color: stringToColor(
"#FFFFFF"),
),
),
SizedBox(
height:
12.rpx),
Text(
day['date'],
// "哈哈",
style: FlutterFlowTheme.of(
context)
.bodyMedium
.override(
fontFamily:
'Readex Pro',
letterSpacing:
0,
fontSize:
22.rpx,
color: stringToColor(
"#929699"),
),
),
SizedBox(
height:
39.rpx),
buildScoreOrIcon(
day['score']),
],
),
),
),
);
})
],
)),
),
],
),
),
),
if (homeController.bindDeviceNum.value != 0)
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
@@ -1011,6 +838,40 @@ class _NewHomePageState extends State<NewHomePage> {
],
);
}
Widget buildScoreOrIcon(dynamic score) {
return SizedBox(
width: 50.rpx,
height: 50.rpx,
child: Center(
child: (score != null)
? FittedBox(
child: Text(
'${score['socre']}',
style: TextStyle(
fontFamily: 'Readex Pro',
fontSize: 40.rpx,
letterSpacing: 0,
color: Colors.white,
),
),
)
: SvgPicture.asset(
'assets/img/icon/close.svg',
width: 25.rpx,
height: 25.rpx,
color: themeController.currentColor.sc3,
),
),
);
}
int? parseToInt(dynamic value) {
if (value == null) return null;
if (value is int) return value;
if (value is String) return int.tryParse(value);
return null;
}
}
class ScoreItem {