增加作弊数据检测

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
+30 -7
View File
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import '../models/data_abnormal_type.dart';
class BatteryInfoPanel extends StatelessWidget {
final double batteryVolt;
@@ -8,6 +9,7 @@ class BatteryInfoPanel extends StatelessWidget {
final double minVolt;
final double maxTemp;
final double minTemp;
final DataAbnormalType abnormalType;
const BatteryInfoPanel({
super.key,
@@ -17,10 +19,15 @@ class BatteryInfoPanel extends StatelessWidget {
required this.minVolt,
required this.maxTemp,
required this.minTemp,
this.abnormalType = DataAbnormalType.none,
});
@override
Widget build(BuildContext context) {
final bool isVoltageAbnormal =
abnormalType == DataAbnormalType.voltageAbnormal;
final Color voltColor = isVoltageAbnormal ? Colors.red : Colors.black;
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -32,6 +39,7 @@ class BatteryInfoPanel extends StatelessWidget {
_buildIcon('voltage'),
'电压',
'${batteryVolt.toStringAsFixed(3)}V',
textColor: voltColor,
),
const SizedBox(height: 8),
Row(
@@ -52,7 +60,12 @@ class BatteryInfoPanel extends StatelessWidget {
color: Colors.red,
),
),
TextSpan(text: '${maxVolt.toStringAsFixed(3)}V'),
TextSpan(
text: '${maxVolt.toStringAsFixed(3)}V',
style: TextStyle(
color: isVoltageAbnormal ? Colors.red : Colors.red,
),
),
],
),
),
@@ -73,7 +86,12 @@ class BatteryInfoPanel extends StatelessWidget {
color: Colors.blue,
),
),
TextSpan(text: '${minVolt.toStringAsFixed(3)}V'),
TextSpan(
text: '${minVolt.toStringAsFixed(3)}V',
style: TextStyle(
color: isVoltageAbnormal ? Colors.red : Colors.blue,
),
),
],
),
),
@@ -96,7 +114,7 @@ class BatteryInfoPanel extends StatelessWidget {
children: [
RichText(
text: TextSpan(
style: TextStyle(
style: const TextStyle(
fontFamily: 'Flyme',
fontSize: 14,
fontWeight: FontWeight.w500,
@@ -117,7 +135,7 @@ class BatteryInfoPanel extends StatelessWidget {
const SizedBox(width: 12),
RichText(
text: TextSpan(
style: TextStyle(
style: const TextStyle(
fontFamily: 'Flyme',
fontSize: 14,
fontWeight: FontWeight.w500,
@@ -165,7 +183,12 @@ class BatteryInfoPanel extends StatelessWidget {
}
}
Widget _buildInfoItem(Widget icon, String label, String value) {
Widget _buildInfoItem(
Widget icon,
String label,
String value, {
Color textColor = Colors.black,
}) {
return Row(
children: [
icon,
@@ -181,11 +204,11 @@ class BatteryInfoPanel extends StatelessWidget {
const SizedBox(width: 6),
Text(
value,
style: const TextStyle(
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.black,
color: textColor,
),
),
],
+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,
),
),
],