增加作弊数据检测

This commit is contained in:
2026-07-30 21:57:08 +08:00
parent c85a523ec0
commit c8717e5e1f
6 changed files with 135 additions and 26 deletions
+28 -10
View File
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import '../models/data_abnormal_type.dart';
class BatterySummary extends StatelessWidget {
final double healthPercent;
final int cycleCount;
final double currentCap;
final int designCap;
final DataAbnormalType abnormalType;
const BatterySummary({
super.key,
@@ -12,11 +14,25 @@ class BatterySummary extends StatelessWidget {
required this.cycleCount,
required this.currentCap,
required this.designCap,
this.abnormalType = DataAbnormalType.none,
});
@override
Widget build(BuildContext context) {
final bool isLowHealth = healthPercent < 70;
final bool isAbnormal = abnormalType != DataAbnormalType.none;
final bool isCapacityAbnormal =
abnormalType == DataAbnormalType.capacityTooLow ||
abnormalType == DataAbnormalType.capacityTooHigh;
// 健康度颜色:异常时红色,否则按阈值
final Color healthColor = isAbnormal
? Colors.red
: (healthPercent < 70 ? Colors.red : Colors.black);
// 容量颜色:异常时红色,否则灰色
final Color capacityColor = isCapacityAbnormal
? Colors.red
: const Color(0xFF5F5F5F);
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
@@ -33,7 +49,7 @@ class BatterySummary extends StatelessWidget {
fontSize: 40,
fontWeight: FontWeight.w500,
height: 1.0,
color: isLowHealth ? Colors.red : Colors.black,
color: healthColor,
),
),
const SizedBox(width: 2),
@@ -44,7 +60,9 @@ class BatterySummary extends StatelessWidget {
fontSize: 20,
fontWeight: FontWeight.w300,
height: 1.0,
color: isLowHealth ? Colors.red : Colors.grey.shade600,
color: healthColor == Colors.red
? Colors.red
: Colors.grey.shade600,
),
),
],
@@ -56,7 +74,7 @@ class BatterySummary extends StatelessWidget {
children: [
RichText(
text: TextSpan(
style: TextStyle(
style: const TextStyle(
fontFamily: 'Flyme',
fontSize: 16,
fontWeight: FontWeight.w500,
@@ -65,9 +83,9 @@ class BatterySummary extends StatelessWidget {
),
children: [
TextSpan(text: '$cycleCount'),
TextSpan(
const TextSpan(
text: ' cycles',
style: const TextStyle(
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
color: Colors.black,
),
@@ -83,7 +101,7 @@ class BatterySummary extends StatelessWidget {
fontSize: 20,
fontWeight: FontWeight.w300,
height: 1.0,
color: const Color(0xFF5F5F5F),
color: capacityColor,
),
children: [
TextSpan(text: currentCap.toStringAsFixed(0)),
@@ -91,17 +109,17 @@ class BatterySummary extends StatelessWidget {
text: ' / ',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
color: const Color(0xFF5F5F5F).withValues(alpha: 0.5),
color: capacityColor.withOpacity(0.5),
),
),
TextSpan(text: designCap.toString()),
TextSpan(
text: ' mAh',
style: const TextStyle(
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color(0xFF5F5F5F),
color: capacityColor,
),
),
],