import 'package:flutter/material.dart'; import '../utils/charge_utils.dart'; /// 充电详情页 class ChargeDetailPage extends StatelessWidget { final String chargeType; final bool isWireless; final double power; final double volt; final double curr; final int? wiredLevel; const ChargeDetailPage({ super.key, required this.chargeType, required this.isWireless, required this.power, required this.volt, required this.curr, this.wiredLevel, }); String _getProtocolDisplay() { if (isWireless) return '无线充电($chargeType)'; if (chargeType == 'PPS') return 'PPS 快充'; if (chargeType == 'SDP') return 'USB 充电'; return chargeType; } /// 🟢 1.5.0 标定档位显示 String _getRequestedDisplay() { return ChargeUtils.getDetailRequestedPowerWired( power, wiredLevel, chargeType, ); } /// 🟢 1.5.0 实际功率显示 String _getActualDisplay() { return ChargeUtils.getDetailActualPowerWired(power, chargeType); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('充电详情'), backgroundColor: Colors.transparent, elevation: 0, foregroundColor: Colors.black, iconTheme: const IconThemeData(color: Colors.black), ), body: Padding( padding: const EdgeInsets.all(20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildDetailRow('协议', _getProtocolDisplay()), const Divider(), // 🟢 1.5.0 有线充电:标定档位 + 实际功率 两行 if (!isWireless) ...[ _buildDetailRow('标定档位', _getRequestedDisplay()), const Divider(), _buildDetailRow('实际功率', _getActualDisplay()), const Divider(), ] else ...[ // 无线充电:保持原样,只显示功率 _buildDetailRow('功率', ChargeUtils.getDisplayPowerWireless(power)), const Divider(), ], _buildDetailRow('电压', '${volt.toStringAsFixed(2)}V'), const Divider(), _buildDetailRow('电流', '${curr.toStringAsFixed(2)}A'), const Divider(), // 辅助信息 if (isWireless) _buildDetailRow('类型', '无线'), if (!isWireless && wiredLevel == null) _buildDetailRow('档位', '自动'), const Spacer(), Center( child: Text( '数据来自 BMS 实时日志', style: TextStyle(fontSize: 12, color: Colors.grey.shade500), ), ), ], ), ), ); } Widget _buildDetailRow(String label, String value) { return Padding( padding: const EdgeInsets.symmetric(vertical: 6.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( label, style: const TextStyle( fontSize: 16, fontWeight: FontWeight.w400, color: Colors.grey, ), ), Text( value, style: const TextStyle( fontSize: 16, fontWeight: FontWeight.w500, color: Colors.black87, ), ), ], ), ); } }