195 lines
6.7 KiB
Dart
195 lines
6.7 KiB
Dart
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/ServiceConstant.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/home_page/SleepDataModuleWidget.dart';
|
||
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 {
|
||
final List<SleepDateWidget> sleepDateWidgets;
|
||
final List<SleepDataModuleWidget> sleepDataModuleWidgets;
|
||
final ThemeController themeController = Get.find();
|
||
final Map targetDevice;
|
||
late ScrollController _scrollController;
|
||
|
||
DynamicReportDetailWidget({
|
||
required this.sleepDateWidgets,
|
||
required this.sleepDataModuleWidgets,
|
||
required this.targetDevice,
|
||
});
|
||
|
||
@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(
|
||
width: double.infinity,
|
||
decoration: BoxDecoration(
|
||
color: themeController.currentColor.sc5,
|
||
borderRadius:
|
||
BorderRadius.circular(AppConstants().normal_container_radius),
|
||
),
|
||
child: Padding(
|
||
padding:
|
||
EdgeInsetsDirectional.fromSTEB(30.rpx, 30.rpx, 30.rpx, 30.rpx),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
_buildHeader(context, targetDevice),
|
||
SizedBox(
|
||
height: 33.rpx,
|
||
),
|
||
_buildSleepDateWidgets(),
|
||
SizedBox(height: 20.rpx),
|
||
_buildSleepDataModuleWidgets(),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
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,
|
||
),
|
||
),
|
||
),
|
||
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();
|
||
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}";
|
||
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,
|
||
),
|
||
),
|
||
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)),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildSleepDateWidgets() {
|
||
return Container(
|
||
width: double.infinity,
|
||
decoration: BoxDecoration(),
|
||
child: SingleChildScrollView(
|
||
controller: _scrollController, // ⭐️ 关键点
|
||
scrollDirection: Axis.horizontal,
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: sleepDateWidgets
|
||
.map((widget) => widget)
|
||
.toList()
|
||
.divide(SizedBox(width: 20.rpx)),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildSleepDataModuleWidgets() {
|
||
bool hasData = sleepDataModuleWidgets.length > 0;
|
||
|
||
if (!hasData) {
|
||
return Container(
|
||
height: 200.rpx,
|
||
alignment: Alignment.center,
|
||
child: Text(
|
||
'暂无数据'.tr,
|
||
style: FlutterFlowTheme.of(Get.context!).bodyMedium.override(
|
||
fontFamily: 'Inter',
|
||
fontSize: 28.rpx,
|
||
color: themeController.currentColor.sc4,
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
return Container(
|
||
width: double.infinity,
|
||
height: 200.rpx,
|
||
child: SingleChildScrollView(
|
||
scrollDirection: Axis.horizontal,
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: sleepDataModuleWidgets
|
||
.map((widget) => widget)
|
||
.toList()
|
||
.divide(SizedBox(width: 14.rpx)),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|