更新日历样式
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.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';
|
||||
|
||||
class SleepdateWidget extends StatelessWidget {
|
||||
@@ -7,17 +8,90 @@ class SleepdateWidget extends StatelessWidget {
|
||||
final bool isSelected;
|
||||
final VoidCallback onTap;
|
||||
final Color highlightColor; // 新增
|
||||
|
||||
const SleepdateWidget({
|
||||
super.key,
|
||||
final Map sleepDate;
|
||||
SleepdateWidget({
|
||||
required this.sleepDate,
|
||||
required this.date,
|
||||
required this.isSelected,
|
||||
required this.onTap,
|
||||
this.highlightColor = Colors.black, // 默认值黑色
|
||||
});
|
||||
|
||||
@override
|
||||
// Widget build(BuildContext context) {
|
||||
// return ClickableContainer(
|
||||
// onTap: onTap,
|
||||
// backgroundColor: Colors.transparent,
|
||||
// highlightColor: Colors.transparent,
|
||||
// padding: EdgeInsets.all(4.rpx),
|
||||
// child: Container(
|
||||
// width: 90.rpx,
|
||||
// height: 90.rpx,
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(30.rpx),
|
||||
// color: isSelected ? highlightColor : Colors.transparent, // 使用传入的颜色
|
||||
// ),
|
||||
// child: Padding(
|
||||
// padding:
|
||||
// EdgeInsetsDirectional.fromSTEB(10.rpx, 10.rpx, 10.rpx, 10.rpx),
|
||||
// child: Container(
|
||||
// decoration: BoxDecoration(
|
||||
// color: Color(0xFF757575),
|
||||
// shape: BoxShape.circle,
|
||||
// ),
|
||||
// alignment: Alignment.center,
|
||||
// child: Text(
|
||||
// '${date.day}',
|
||||
// style: TextStyle(
|
||||
// color: Colors.white,
|
||||
// fontSize: 26.rpx,
|
||||
// letterSpacing: 0.0,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Color? fillColor;
|
||||
|
||||
// 判断是否存在 score 数据
|
||||
final List<dynamic>? dataList = sleepDate['scoreList']?['data'];
|
||||
final List<dynamic>? typeList = sleepDate['scoreList']?['type'];
|
||||
|
||||
if (dataList != null && typeList != null) {
|
||||
// 查找是否有匹配日期的数据
|
||||
for (var item in dataList) {
|
||||
final st = item['st'];
|
||||
final level = item['level'];
|
||||
|
||||
if (st is int) {
|
||||
final itemDate =
|
||||
DateTime.fromMillisecondsSinceEpoch(st).toLocal(); // 转为本地时间
|
||||
|
||||
// 判断是否是同一天
|
||||
if (itemDate.year == date.year &&
|
||||
itemDate.month == date.month &&
|
||||
itemDate.day == date.day) {
|
||||
// 找到对应 level 的颜色
|
||||
final matchType = typeList.firstWhere(
|
||||
(e) => e['level'] == level,
|
||||
orElse: () => null,
|
||||
);
|
||||
|
||||
if (matchType != null && matchType['color'] != null) {
|
||||
final hexColor = matchType['color'];
|
||||
fillColor = stringToColor(hexColor);
|
||||
}
|
||||
|
||||
break; // 找到就跳出
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ClickableContainer(
|
||||
onTap: onTap,
|
||||
backgroundColor: Colors.transparent,
|
||||
@@ -28,14 +102,14 @@ class SleepdateWidget extends StatelessWidget {
|
||||
height: 90.rpx,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(30.rpx),
|
||||
color: isSelected ? highlightColor : Colors.transparent, // 使用传入的颜色
|
||||
color: isSelected ? highlightColor : Colors.transparent,
|
||||
),
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsetsDirectional.fromSTEB(10.rpx, 10.rpx, 10.rpx, 10.rpx),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFF757575),
|
||||
color: fillColor ?? Color(0xFF757575), // 如果匹配不到就默认灰色
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
|
||||
Reference in New Issue
Block a user