更新样式

This commit is contained in:
wyf
2025-12-01 15:41:34 +08:00
parent 991bf97fd1
commit 1cc26aa46d
18 changed files with 502 additions and 677 deletions

View File

@@ -199,6 +199,7 @@ class _LineChartByRangePainter extends CustomPainter {
for (var item in data) {
int start = item['startTime'];
int end = item['endTime'];
// int times = item['times'];
int times = item['times'];
double startX = xStart * 2 +

View File

@@ -29,41 +29,112 @@ class SleepRadarChart extends StatelessWidget {
);
}
// Widget _buildRadarChart() {
// return AspectRatio(
// aspectRatio: 1.3,
// child: RadarChart(
// RadarChartData(
// dataSets: [
// // 今日数据
// RadarDataSet(
// dataEntries: data
// .map((e) => RadarEntry(value: (e['t'] as num).toDouble()))
// .toList(),
// borderColor: stringToColor("#00C1AA"),
// borderWidth: 2,
// fillColor: Colors.transparent,
// entryRadius: 0,
// ),
// // 昨日数据
// RadarDataSet(
// dataEntries: data
// .map((e) => RadarEntry(value: (e['y'] as num).toDouble()))
// .toList(),
// borderColor: stringToColor("#FFD251"),
// borderWidth: 2,
// fillColor: Colors.transparent,
// entryRadius: 0,
// ),
// ],
// radarBackgroundColor: stringToColor("#343844").withOpacity(0.6),
// radarBorderData: BorderSide(
// color: themeController.currentColor.sc4, width: 0.5.rpx),
// radarShape: RadarShape.polygon,
// titlePositionPercentageOffset: 0.2,
// titleTextStyle: TextStyle(
// fontSize: AppConstants().normal_text_fontSize,
// color: themeController.currentColor.sc3),
// getTitle: (index, angle) {
// return RadarChartTitle(text: data[index]['name'] ?? '未知'.tr);
// },
// tickCount: 5,
// ticksTextStyle:
// const TextStyle(color: Colors.transparent, fontSize: 10),
// gridBorderData: BorderSide(color: Colors.transparent, width: 1),
// tickBorderData: BorderSide(
// color: themeController.currentColor.sc4, width: 0.5.rpx),
// ),
// swapAnimationDuration: const Duration(milliseconds: 400),
// ),
// );
// }
Widget _buildRadarChart() {
// 判断 t 是否全为 0今日
final bool isTodayAllZero =
data.every((e) => (e['t'] as num).toDouble() == 0);
// 判断 y 是否全为 0昨日
final bool isYesterdayAllZero =
data.every((e) => (e['y'] as num).toDouble() == 0);
// 构建 dataSets
final List<RadarDataSet> dataSets = [];
// 今日数据(非全 0 才加入)
if (!isTodayAllZero) {
dataSets.add(
RadarDataSet(
dataEntries: data
.map((e) => RadarEntry(value: (e['t'] as num).toDouble()))
.toList(),
borderColor: stringToColor("#00C1AA"),
borderWidth: 2,
fillColor: Colors.transparent,
entryRadius: 0,
),
);
}
// 昨日数据(非全 0 才加入)
if (!isYesterdayAllZero) {
dataSets.add(
RadarDataSet(
dataEntries: data
.map((e) => RadarEntry(value: (e['y'] as num).toDouble()))
.toList(),
borderColor: stringToColor("#FFD251"),
borderWidth: 2,
fillColor: Colors.transparent,
entryRadius: 0,
),
);
}
return AspectRatio(
aspectRatio: 1.3,
child: RadarChart(
RadarChartData(
dataSets: [
// 今日数据
RadarDataSet(
dataEntries: data
.map((e) => RadarEntry(value: (e['t'] as num).toDouble()))
.toList(),
borderColor: stringToColor("#00C1AA"),
borderWidth: 2,
fillColor: Colors.transparent,
entryRadius: 0,
),
// 昨日数据
RadarDataSet(
dataEntries: data
.map((e) => RadarEntry(value: (e['y'] as num).toDouble()))
.toList(),
borderColor: stringToColor("#FFD251"),
borderWidth: 2,
fillColor: Colors.transparent,
entryRadius: 0,
),
],
dataSets: dataSets,
radarBackgroundColor: stringToColor("#343844").withOpacity(0.6),
radarBorderData: BorderSide(
color: themeController.currentColor.sc4, width: 0.5.rpx),
radarShape: RadarShape.polygon,
titlePositionPercentageOffset: 0.2,
titleTextStyle: TextStyle(
fontSize: AppConstants().normal_text_fontSize,
color: themeController.currentColor.sc3),
fontSize: AppConstants().normal_text_fontSize,
color: themeController.currentColor.sc3,
),
getTitle: (index, angle) {
return RadarChartTitle(text: data[index]['name'] ?? '未知'.tr);
},

View File

@@ -83,8 +83,13 @@ class _BreatheCardState extends State<BreatheCard>
return Container();
}
// List data = widget.sleepReport['brs'] ?? [];
List data = widget.sleepReport['brs'] ?? [];
data = data.where((item) {
return item['show'] != false; // 只保留 show 不为 false 的元素
}).toList(); // 添加 .toList()
return Container(
width: double.infinity,
decoration: BoxDecoration(

View File

@@ -25,10 +25,11 @@ Widget DailyDataWidget(
GlobalKey breatheCardKey,
dynamic data,
) {
List<Widget> _buildSectionList() {
EdgeInsetsDirectional padding =
EdgeInsetsDirectional.fromSTEB(30.rpx, 0, 30.rpx, 25.rpx);
return [
SleepScoreWidget(sleepReport: sleepReport),
SleepViewWidget(sleepReport: sleepReport),

View File

@@ -15,7 +15,8 @@ class HeartRateCard extends StatefulWidget {
State<HeartRateCard> createState() => _HeartRateCardState();
}
class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateMixin {
class _HeartRateCardState extends State<HeartRateCard>
with TickerProviderStateMixin {
final GlobalKey _highlightKey = GlobalKey();
AnimationController? _animationController;
bool _shouldAnimate = false;
@@ -30,9 +31,10 @@ class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateM
_shouldAnimate = true;
_initAnimation();
}
WidgetsBinding.instance.addPostFrameCallback((_) {
if (widget.highlightItem != null && _highlightKey.currentContext != null) {
if (widget.highlightItem != null &&
_highlightKey.currentContext != null) {
Scrollable.ensureVisible(
_highlightKey.currentContext!,
duration: Duration(milliseconds: 500),
@@ -67,7 +69,7 @@ class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateM
}
}
});
_animationController!.forward();
}
@@ -86,8 +88,16 @@ class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateM
return Container();
}
// List data = widget.sleepReport['hrs'] ?? [];
// data = data.where((item) {
// return item['show'] != false; // 只保留 show 不为 false 的元素
// });
List data = widget.sleepReport['hrs'] ?? [];
data = data.where((item) {
return item['show'] != false; // 只保留 show 不为 false 的元素
}).toList(); // 添加 .toList()
return Container(
width: double.infinity,
decoration: BoxDecoration(
@@ -104,9 +114,9 @@ class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateM
children: List.generate(data.length, (index) {
final item = data[index];
item['showTip'] = true;
final bool isHighlighted = _shouldAnimate &&
item['id'] == _highlightedId;
final bool isHighlighted =
_shouldAnimate && item['id'] == _highlightedId;
return SizedBox(
width: (MediaQuery.of(context).size.width - 160.rpx) / 3,
child: AnimatedBuilder(
@@ -118,7 +128,8 @@ class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateM
? BoxDecoration(
border: Border.all(
color: themeController.currentColor.sc2
.withOpacity(_animationController?.value ?? 0),
.withOpacity(
_animationController?.value ?? 0),
width: 1.rpx,
),
borderRadius: BorderRadius.circular(8),
@@ -138,4 +149,4 @@ class _HeartRateCardState extends State<HeartRateCard> with TickerProviderStateM
return Container();
}
}
}
}

View File

@@ -842,40 +842,7 @@ class _NewSleepReportPageState extends State<NewSleepReportPage> {
],
),
),
),
// Obx(() {
// if (sleepReportController.isLoading.value) {
// return Center(
// child: CircularProgressIndicator(
// strokeWidth: 2,
// valueColor: AlwaysStoppedAnimation<Color>(
// themeController.currentColor.sc1,
// ),
// ),
// );
// }
// switch (sleepReportController.model.type) {
// case 1:
// return DailyDataWidget(
// sleepReport,
// sleepCardKey,
// heartRateCardKey,
// breatheCardKey,
// widget.data);
// case 2:
// return WeekDataWidget(
// sleepReport,
// widget.data,
// );
// case 3:
// return MonthDataWidget(
// sleepReport,
// widget.data,
// );
// default:
// return NullDataWidget();
// }
// }),
),
Obx(() {
if (sleepReportController.isLoading.value) {
return Center(