176 lines
5.1 KiB
Dart
176 lines
5.1 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.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({
|
||
Key? key,
|
||
required this.chargeType,
|
||
required this.isWireless,
|
||
required this.power,
|
||
required this.volt,
|
||
required this.curr,
|
||
this.wiredLevel,
|
||
}) : super(key: key);
|
||
|
||
String _getProtocolDisplay() {
|
||
if (isWireless) return '无线充电($chargeType)';
|
||
if (chargeType == 'PPS') return 'PPS 快充';
|
||
if (chargeType == 'SDP') return 'USB 充电';
|
||
return chargeType;
|
||
}
|
||
|
||
String _getRequestedDisplay() {
|
||
return ChargeUtils.getDetailRequestedPowerWired(
|
||
power,
|
||
wiredLevel,
|
||
chargeType,
|
||
);
|
||
}
|
||
|
||
String _getActualDisplay() {
|
||
return ChargeUtils.getDetailActualPowerWired(power, chargeType);
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||
value: const SystemUiOverlayStyle(
|
||
statusBarColor: Color.fromRGBO(157, 212, 237, 0.1),
|
||
statusBarIconBrightness: Brightness.dark,
|
||
statusBarBrightness: Brightness.dark,
|
||
),
|
||
child: Scaffold(
|
||
backgroundColor: Colors.white,
|
||
appBar: AppBar(
|
||
title: const Text('充电详情'),
|
||
backgroundColor: Colors.white,
|
||
elevation: 0,
|
||
scrolledUnderElevation: 0,
|
||
shadowColor: Colors.transparent,
|
||
surfaceTintColor: Colors.transparent,
|
||
foregroundColor: Colors.black,
|
||
iconTheme: const IconThemeData(color: Colors.black),
|
||
),
|
||
body: Padding(
|
||
padding: const EdgeInsets.all(20.0),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
_buildTextRow('协议', _getProtocolDisplay()),
|
||
const Divider(),
|
||
|
||
if (!isWireless) ...[
|
||
_buildTextRow('标定档位', _getRequestedDisplay()),
|
||
const Divider(),
|
||
_buildTextRow('实际功率', _getActualDisplay()),
|
||
const Divider(),
|
||
] else ...[
|
||
_buildTextRow('功率', ChargeUtils.getDisplayPowerWireless(power)),
|
||
const Divider(),
|
||
],
|
||
|
||
_buildDetailRow('电压', volt, 'V'),
|
||
const Divider(),
|
||
_buildDetailRow('电流', curr, 'A'),
|
||
const Divider(),
|
||
|
||
if (isWireless) _buildTextRow('类型', '无线'),
|
||
if (!isWireless && wiredLevel == null) _buildTextRow('档位', '自动'),
|
||
|
||
const Spacer(),
|
||
Center(
|
||
child: Text(
|
||
'数据来自 BMS 实时日志',
|
||
style: TextStyle(
|
||
fontFamily: 'HarmonyOS_Sans_SC',
|
||
fontSize: 12,
|
||
color: Colors.grey.shade500,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 纯文本行(协议、功率、档位等)
|
||
Widget _buildTextRow(String label, String value) {
|
||
return Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
label,
|
||
style: const TextStyle(
|
||
fontFamily: 'HarmonyOS_Sans_SC',
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.w400,
|
||
color: Colors.grey,
|
||
),
|
||
),
|
||
Text(
|
||
value,
|
||
style: const TextStyle(
|
||
fontFamily: 'HarmonyOS_Sans_SC', // 复杂字符串保持 Harmony
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.w500,
|
||
color: Colors.black87,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
/// 数值行(电压/电流,数字用 Flyme,单位用 Harmony)
|
||
Widget _buildDetailRow(String label, double value, String unit) {
|
||
return Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Text(
|
||
label,
|
||
style: const TextStyle(
|
||
fontFamily: 'HarmonyOS_Sans_SC',
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.w400,
|
||
color: Colors.grey,
|
||
),
|
||
),
|
||
RichText(
|
||
text: TextSpan(
|
||
style: const TextStyle(
|
||
fontSize: 16,
|
||
fontWeight: FontWeight.w500,
|
||
color: Colors.black87,
|
||
),
|
||
children: [
|
||
TextSpan(
|
||
text: value.toStringAsFixed(2),
|
||
style: const TextStyle(fontFamily: 'Flyme'), // 🟢 数字用 Flyme
|
||
),
|
||
TextSpan(
|
||
text: unit,
|
||
style: const TextStyle(fontFamily: 'HarmonyOS_Sans_SC'),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|