更新睡眠报告

This commit is contained in:
wyf
2025-05-29 20:20:49 +08:00
parent b34737dbe8
commit 7a816922fa
41 changed files with 4604 additions and 2394 deletions

View File

@@ -3,68 +3,138 @@ 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:EasyDartModule/EasyDartModule.dart' as es;
class HeartRateCard extends StatefulWidget {
var sleepReport;
HeartRateCard({super.key, required this.sleepReport});
final int? highlightItem;
HeartRateCard({super.key, required this.sleepReport, this.highlightItem});
@override
State<HeartRateCard> createState() => _HeartRateCardState();
}
class _HeartRateCardState extends State<HeartRateCard> {
@override
void setState(VoidCallback callback) {
super.setState(callback);
}
class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateMixin {
final GlobalKey _highlightKey = GlobalKey();
AnimationController? _animationController;
bool _shouldAnimate = false;
int? _highlightedId;
int _flashCount = 0; // 用于跟踪闪烁次数
@override
void initState() {
super.initState();
if (widget.highlightItem != null) {
_highlightedId = widget.highlightItem;
_shouldAnimate = true;
_initAnimation();
}
WidgetsBinding.instance.addPostFrameCallback((_) {
if (widget.highlightItem != null && _highlightKey.currentContext != null) {
Scrollable.ensureVisible(
_highlightKey.currentContext!,
duration: Duration(milliseconds: 500),
curve: Curves.easeInOut,
alignment: 0.3,
);
}
});
}
void _initAnimation() {
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 300),
)..addStatusListener((status) {
if (status == AnimationStatus.completed) {
// 正向动画完成,开始反向动画
_animationController!.reverse();
} else if (status == AnimationStatus.dismissed) {
// 反向动画完成,增加计数
_flashCount++;
// 闪烁3次后停止
if (_flashCount >= 5) {
_animationController!.dispose();
setState(() {
_shouldAnimate = false;
_highlightedId = null;
});
} else {
// 继续下一次闪烁
_animationController!.forward();
}
}
});
_animationController!.forward();
}
@override
void dispose() {
_animationController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (widget.sleepReport == null ||
widget.sleepReport is! Map ||
widget.sleepReport.isEmpty) {
try {
if (widget.sleepReport == null ||
widget.sleepReport is! Map ||
widget.sleepReport.isEmpty) {
return Container();
}
List data = widget.sleepReport['hrs'] ?? [];
return Container(
width: double.infinity,
decoration: BoxDecoration(
color: themeController.currentColor.sc5,
borderRadius:
BorderRadius.circular(AppConstants().normal_container_radius),
),
child: Padding(
padding:
EdgeInsetsDirectional.fromSTEB(26.rpx, 29.rpx, 26.rpx, 45.rpx),
child: Wrap(
spacing: 23.rpx,
runSpacing: 25.rpx,
children: List.generate(data.length, (index) {
final item = data[index];
item['showTip'] = true;
final bool isHighlighted = _shouldAnimate &&
item['id'] == _highlightedId;
return SizedBox(
width: (MediaQuery.of(context).size.width - 160.rpx) / 3,
child: AnimatedBuilder(
animation: _animationController ?? AlwaysStoppedAnimation(0),
builder: (context, child) {
return Container(
key: isHighlighted ? _highlightKey : null,
decoration: isHighlighted
? BoxDecoration(
border: Border.all(
color: themeController.currentColor.sc2
.withOpacity(_animationController?.value ?? 0),
width: 1.rpx,
),
borderRadius: BorderRadius.circular(8),
)
: null,
child: SleepDataModuleWidget(data: item),
);
},
),
);
}),
),
),
);
} catch (e) {
es.EasyDartModule.logger.error("心率监测绘制异常${e}");
return Container();
}
List data = widget.sleepReport['hrs'] ?? [];
return Container(
width: double.infinity,
decoration: BoxDecoration(
color: themeController.currentColor.sc5,
borderRadius:
BorderRadius.circular(AppConstants().normal_container_radius),
),
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(26.rpx, 29.rpx, 26.rpx, 45.rpx),
child: Wrap(
spacing: 23.rpx, // 横向间距(左右间距如需加可设置)
runSpacing: 25.rpx, // 每行之间的垂直间距
children: List.generate(data.length, (index) {
final item = data[index];
item['showTip'] = true;
return SizedBox(
width: (MediaQuery.of(context).size.width - 160.rpx) / 3,
child: SleepDataModuleWidget(data: item),
// child: Container(
// width: 20,
// height: 20,
// color: Colors.red,
// ),
);
}),
),
),
);
}
}
}