更新睡眠报告
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)),
|
||||
|
||||
Reference in New Issue
Block a user