import 'package:flutter/material.dart'; import '../models/data_abnormal_type.dart'; import '../theme/app_colors.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 c = context.colors; final bool isAbnormal = abnormalType != DataAbnormalType.none; final bool isCapacityAbnormal = abnormalType == DataAbnormalType.capacityTooLow || abnormalType == DataAbnormalType.capacityTooHigh; final Color healthColor = isAbnormal ? c.healthRed : (healthPercent < 70 ? c.healthRed : c.textPrimary); final Color capacityColor = isCapacityAbnormal ? c.healthRed : c.textSecondary; 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 == c.healthRed ? c.healthRed : c.textSecondary, ), ), ], ), const Spacer(), Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ RichText( text: TextSpan( style: TextStyle( fontFamily: 'Flyme', fontSize: 16, fontWeight: FontWeight.w500, height: 1.2, color: c.textPrimary, ), children: [ TextSpan(text: '$cycleCount'), TextSpan( text: ' cycles', style: TextStyle( fontFamily: 'HarmonyOS_Sans_SC', color: c.textPrimary, ), ), ], ), ), 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, ), ), ], ), ), ], ), ], ); } }