更新睡眠报告
This commit is contained in:
@@ -11,33 +11,50 @@ import 'package:vbvs_app/component/home_page/SleepDateWidget.dart';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
|
||||
class DynamicReportDetailWidget extends StatelessWidget {
|
||||
class DynamicReportDetailWidget extends StatefulWidget {
|
||||
final List<SleepDateWidget> sleepDateWidgets;
|
||||
final List<SleepDataModuleWidget> sleepDataModuleWidgets;
|
||||
final ThemeController themeController = Get.find();
|
||||
final Map targetDevice;
|
||||
late ScrollController _scrollController;
|
||||
|
||||
DynamicReportDetailWidget({
|
||||
const DynamicReportDetailWidget({
|
||||
Key? key,
|
||||
required this.sleepDateWidgets,
|
||||
required this.sleepDataModuleWidgets,
|
||||
required this.targetDevice,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<DynamicReportDetailWidget> createState() =>
|
||||
_DynamicReportDetailWidgetState();
|
||||
}
|
||||
|
||||
class _DynamicReportDetailWidgetState extends State<DynamicReportDetailWidget> {
|
||||
final ThemeController themeController = Get.find();
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
bool _hasScrolled = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Future.delayed(Duration(milliseconds: 100), () {
|
||||
if (!_hasScrolled &&
|
||||
_scrollController.hasClients &&
|
||||
_scrollController.position.maxScrollExtent > 0) {
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
_hasScrolled = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_scrollController = ScrollController();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_scrollController.hasClients) {
|
||||
// _scrollController.jumpTo(_scrollController.position.maxScrollExtent);
|
||||
// 如果你希望有动画,用下面这句替代 jumpTo:
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 25.rpx, 0, 25.rpx),
|
||||
child: Container(
|
||||
@@ -53,10 +70,8 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
_buildHeader(context, targetDevice),
|
||||
SizedBox(
|
||||
height: 33.rpx,
|
||||
),
|
||||
_buildHeader(context, widget.targetDevice),
|
||||
SizedBox(height: 33.rpx),
|
||||
_buildSleepDateWidgets(),
|
||||
SizedBox(height: 20.rpx),
|
||||
_buildSleepDataModuleWidgets(),
|
||||
@@ -68,88 +83,81 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildHeader(BuildContext context, Map targetDevice) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: themeController.currentColor.sc3.withOpacity(0.2),
|
||||
borderRadius: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () async {
|
||||
await Get.toNamed("/bodyDevice", arguments: targetDevice);
|
||||
},
|
||||
child: Text(
|
||||
'${targetDevice['person']?['name'] == null ? '未命名'.tr : targetDevice['person']['name']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 30.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: themeController.currentColor.sc3.withOpacity(0.2),
|
||||
borderRadius: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () async {
|
||||
await Get.toNamed("/bodyDevice", arguments: targetDevice);
|
||||
},
|
||||
child: Text(
|
||||
'${targetDevice['person']?['name'] == null ? '未命名'.tr : targetDevice['person']['name']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 30.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
borderRadius: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () {
|
||||
String mac = targetDevice['mac'];
|
||||
List<SleepDateWidget> selectedWidgets = sleepDateWidgets
|
||||
.where(
|
||||
(widget) => widget.isSelected == true,
|
||||
)
|
||||
.toList();
|
||||
),
|
||||
ClickableContainer(
|
||||
backgroundColor: Colors.transparent,
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
borderRadius: 0,
|
||||
padding: EdgeInsets.zero,
|
||||
onTap: () {
|
||||
String mac = targetDevice['mac'];
|
||||
List<SleepDateWidget> selectedWidgets = widget.sleepDateWidgets
|
||||
.where((w) => w.isSelected == true)
|
||||
.toList();
|
||||
if (selectedWidgets.isNotEmpty) {
|
||||
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
|
||||
int.parse(selectedWidgets[0].time!));
|
||||
String time = MyUtils.formatBindTime(dateTime);
|
||||
String sleepReportUrl =
|
||||
"${ServiceConstant.sleep_report_url}?mac=${mac}&token=${ServiceConstant.sleep_token}&date=${time}";
|
||||
"${ServiceConstant.sleep_report_url}?mac=$mac&token=${ServiceConstant.sleep_token}&date=$time";
|
||||
Get.toNamed("/sleepReportPage", arguments: sleepReportUrl);
|
||||
},
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Text(
|
||||
'首页.报告详情'.tr,
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 26.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'首页.报告详情'.tr,
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 26.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 6.rpx, 0, 0.rpx),
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/arrow_right.svg',
|
||||
width: 14.rpx,
|
||||
height: 14.rpx,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(0, 6.rpx, 0, 0.rpx),
|
||||
child: SvgPicture.asset(
|
||||
'assets/img/icon/arrow_right.svg',
|
||||
width: 14.rpx,
|
||||
height: 14.rpx,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
),
|
||||
].divide(SizedBox(width: 22.rpx)),
|
||||
),
|
||||
),
|
||||
].divide(SizedBox(width: 22.rpx)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSleepDateWidgets() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(),
|
||||
child: SingleChildScrollView(
|
||||
controller: _scrollController, // ⭐️ 关键点
|
||||
controller: _scrollController,
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: sleepDateWidgets
|
||||
children: widget.sleepDateWidgets
|
||||
.map((widget) => widget)
|
||||
.toList()
|
||||
.divide(SizedBox(width: 20.rpx)),
|
||||
@@ -159,15 +167,13 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildSleepDataModuleWidgets() {
|
||||
bool hasData = sleepDataModuleWidgets.length > 0;
|
||||
|
||||
if (!hasData) {
|
||||
if (widget.sleepDataModuleWidgets.isEmpty) {
|
||||
return Container(
|
||||
height: 200.rpx,
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'暂无数据'.tr,
|
||||
style: FlutterFlowTheme.of(Get.context!).bodyMedium.override(
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 28.rpx,
|
||||
color: themeController.currentColor.sc4,
|
||||
@@ -182,8 +188,7 @@ class DynamicReportDetailWidget extends StatelessWidget {
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: sleepDataModuleWidgets
|
||||
children: widget.sleepDataModuleWidgets
|
||||
.map((widget) => widget)
|
||||
.toList()
|
||||
.divide(SizedBox(width: 14.rpx)),
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||||
import 'package:vbvs_app/controller/sleep/sleep_report_controller.dart';
|
||||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||||
import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart';
|
||||
|
||||
class SleepDataModuleWidget extends StatefulWidget {
|
||||
final Map<String, dynamic> data;
|
||||
@@ -37,11 +40,192 @@ class _SleepDataModuleWidgetState extends State<SleepDataModuleWidget> {
|
||||
ThemeController themeController = Get.find();
|
||||
return ClickableContainer(
|
||||
backgroundColor: themeController.currentColor.sc5,
|
||||
highlightColor: themeController.currentColor.sc3,
|
||||
highlightColor: themeController.currentColor.sc21,
|
||||
borderRadius: 20.rpx,
|
||||
padding: EdgeInsetsDirectional.fromSTEB(18.rpx, 18.rpx, 18.rpx, 22.rpx),
|
||||
padding: EdgeInsetsDirectional.fromSTEB(18.rpx, 10.rpx, 18.rpx, 10.rpx),
|
||||
onTap: () {
|
||||
print('点击了离床次数卡片');
|
||||
if (widget.data['showTip'] != null && widget.data['showTip'] == true) {
|
||||
final String itemLevel = widget.data['code'] ?? '';
|
||||
SleepReportController sleepReportController = Get.find();
|
||||
|
||||
var report = sleepReportController.sleepReport;
|
||||
List<Map<String, dynamic>> levelGroups = [];
|
||||
|
||||
if (report != null) {
|
||||
var colorMap =
|
||||
Map<String, dynamic>.from(report.value['info']['color']);
|
||||
var levelMap =
|
||||
Map<String, dynamic>.from(report.value['info']['level']);
|
||||
|
||||
for (var prefix in ['G', 'R', 'Y']) {
|
||||
List<String> keys =
|
||||
colorMap.keys.where((k) => k.startsWith(prefix)).toList();
|
||||
keys.sort(); // G1, G2, G3
|
||||
|
||||
List<Map<String, dynamic>> items = keys.map((k) {
|
||||
return {
|
||||
"key": k,
|
||||
"color": colorMap[k],
|
||||
"level": levelMap[k] ?? "未知",
|
||||
};
|
||||
}).toList();
|
||||
|
||||
levelGroups.add({
|
||||
"levelName": items.first['level'], // 默认同组level一致
|
||||
"items": items,
|
||||
});
|
||||
}
|
||||
}
|
||||
showTipDialog(
|
||||
backgroundColor: stringToColor("#FFFFFF"),
|
||||
context,
|
||||
Column(
|
||||
children: [
|
||||
Text(
|
||||
"${widget.data['name']}",
|
||||
style: TextStyle(
|
||||
color: stringToColor("#333333"),
|
||||
fontSize: 36.rpx,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 17.rpx,
|
||||
),
|
||||
Text(
|
||||
(widget.data['tips']?.toString().trim().isNotEmpty ?? false)
|
||||
? widget.data['tips'].toString()
|
||||
: "未知数据".tr,
|
||||
style: TextStyle(
|
||||
color: stringToColor("#C8CBD2"),
|
||||
fontSize: 26.rpx,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 37.rpx,
|
||||
),
|
||||
Text(
|
||||
"${widget.data['value']}",
|
||||
style: TextStyle(
|
||||
color: stringToColor("${widget.data['color']}"),
|
||||
fontSize: 60.rpx,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 81.rpx,
|
||||
),
|
||||
IntrinsicHeight(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
for (int i = 0; i < levelGroups.length; i++) ...[
|
||||
// 每个 levelGroup 区域
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Level 名称
|
||||
Text(
|
||||
levelGroups[i]['levelName'],
|
||||
style: TextStyle(
|
||||
fontSize: 30.rpx,
|
||||
color: stringToColor("#333333"),
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 38.rpx),
|
||||
|
||||
// 颜色圆点 + key(包一层,和 svg 分离)
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start, // 上对齐,避免撑高分割线
|
||||
children:
|
||||
levelGroups[i]['items'].map<Widget>((item) {
|
||||
final bool isSelected =
|
||||
(item['key'] == itemLevel);
|
||||
return Column(
|
||||
children: [
|
||||
// 颜色圆点 + key(参与分割线高度)
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 20.rpx,
|
||||
height: 20.rpx,
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
stringToColor(item['color']),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 30.rpx),
|
||||
Text(
|
||||
item['key'],
|
||||
style: TextStyle(
|
||||
color: stringToColor("#333333"),
|
||||
fontSize: 20.rpx,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// svg 箭头(不影响分割线高度)
|
||||
SizedBox(height: 20.rpx),
|
||||
isSelected
|
||||
? SvgPicture.asset(
|
||||
'assets/img/icon/triangle.svg',
|
||||
width: 18.rpx,
|
||||
height: 18.rpx,
|
||||
color: themeController
|
||||
.currentColor.sc9,
|
||||
)
|
||||
: SizedBox(height: 18.rpx),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 分割线(只和主要内容等高)
|
||||
if (i != levelGroups.length - 1)
|
||||
Container(
|
||||
width: 1.rpx,
|
||||
color: stringToColor("${widget.data['color']}"),
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.rpx),
|
||||
),
|
||||
]
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 71.rpx,
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: "当前属于".tr, // 第一部分文本
|
||||
style: TextStyle(
|
||||
color: Colors.black, // 你想要的样式
|
||||
fontSize: 30.rpx,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: itemLevel, // 第二部分文本
|
||||
style: TextStyle(
|
||||
color: stringToColor("${widget.data['color']}"),
|
||||
fontSize: 30.rpx,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
// width: MediaQuery.sizeOf(context).width * 0.267,
|
||||
@@ -78,7 +262,7 @@ class _SleepDataModuleWidgetState extends State<SleepDataModuleWidget> {
|
||||
'${widget.data['value']}',
|
||||
style: FlutterFlowTheme.of(context).bodyMedium.override(
|
||||
fontFamily: 'Inter',
|
||||
fontSize: 40.rpx,
|
||||
fontSize: 36.rpx,
|
||||
letterSpacing: 0.0,
|
||||
color: themeController.currentColor.sc3,
|
||||
),
|
||||
@@ -120,7 +304,7 @@ class _SleepDataModuleWidgetState extends State<SleepDataModuleWidget> {
|
||||
alignment: Alignment.center,
|
||||
constraints: BoxConstraints(
|
||||
minWidth: 43.rpx,
|
||||
minHeight: 36.rpx,
|
||||
minHeight: 25.rpx,
|
||||
),
|
||||
child: Text(
|
||||
'${widget.data['level']}',
|
||||
|
||||
@@ -122,7 +122,7 @@ class _TopSlideNotificationState extends State<TopSlideNotification>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Positioned(
|
||||
top: 0,
|
||||
top: 140.rpx,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: SlideTransition(
|
||||
@@ -130,7 +130,7 @@ class _TopSlideNotificationState extends State<TopSlideNotification>
|
||||
child: Material(
|
||||
color: stringToColor("#000000").withOpacity(0.8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 20.0),
|
||||
padding: EdgeInsets.symmetric(vertical: 20.rpx),
|
||||
child: Container(
|
||||
child: Text(
|
||||
widget.text,
|
||||
|
||||
Reference in New Issue
Block a user