134 lines
4.0 KiB
Dart
134 lines
4.0 KiB
Dart
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,
|
|
required this.healthPercent,
|
|
required this.cycleCount,
|
|
required this.currentCap,
|
|
required this.designCap,
|
|
this.abnormalType = DataAbnormalType.none,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
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,
|
|
children: [
|
|
// 健康度大数字
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
textBaseline: TextBaseline.alphabetic,
|
|
children: [
|
|
Text(
|
|
healthPercent.toStringAsFixed(1),
|
|
style: TextStyle(
|
|
fontFamily: 'Flyme',
|
|
fontSize: 40,
|
|
fontWeight: FontWeight.w500,
|
|
height: 1.0,
|
|
color: healthColor,
|
|
),
|
|
),
|
|
const SizedBox(width: 2),
|
|
Text(
|
|
'%',
|
|
style: TextStyle(
|
|
fontFamily: 'Flyme',
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w300,
|
|
height: 1.0,
|
|
color: healthColor == Colors.red
|
|
? Colors.red
|
|
: Colors.grey.shade600,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
// cycles + mAh
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
RichText(
|
|
text: TextSpan(
|
|
style: const TextStyle(
|
|
fontFamily: 'Flyme',
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
height: 1.2,
|
|
color: Colors.black,
|
|
),
|
|
children: [
|
|
TextSpan(text: '$cycleCount'),
|
|
const TextSpan(
|
|
text: ' cycles',
|
|
style: TextStyle(
|
|
fontFamily: 'HarmonyOS_Sans_SC',
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
RichText(
|
|
text: TextSpan(
|
|
style: TextStyle(
|
|
fontFamily: 'Flyme',
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.w300,
|
|
height: 1.0,
|
|
color: capacityColor,
|
|
),
|
|
children: [
|
|
TextSpan(text: currentCap.toStringAsFixed(0)),
|
|
TextSpan(
|
|
text: ' / ',
|
|
style: TextStyle(
|
|
fontFamily: 'HarmonyOS_Sans_SC',
|
|
color: capacityColor.withOpacity(0.5),
|
|
),
|
|
),
|
|
TextSpan(text: designCap.toString()),
|
|
TextSpan(
|
|
text: ' mAh',
|
|
style: TextStyle(
|
|
fontFamily: 'HarmonyOS_Sans_SC',
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
color: capacityColor,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|