13 Commits

14 changed files with 437 additions and 169 deletions
+14 -5
View File
@@ -24,9 +24,10 @@
| 版本 | 主题 | 状态 |
| :--- | :--- | :--- |
| 1.4.0 | SAF 权限改造 | ✅ 已发布 |
| 1.5.0 | 功率计算优化 | 📋 规划中 |
| 2.0.0 | 数据看板扩展(月/季/年趋势) | 📋 远景 |
| 1.5.0 | 功率计算优化 | ✅ 已发布 |
| 1.5.2 | 部分场景字体替换 | ✅ 已发布 |
| 1.6.0 | 更新日志独立页面 | 📋近期开发 |
| 2.0.0 | 数据看板扩展等系列更新 | 📋 远景 |
---
@@ -34,7 +35,14 @@
- Flutter SDK: ^3.9.2
- Android: 8.0+ (API 26+)
- 仅支持魅族手机(15 系列 ~ 25 系列)
---
## 机型匹配情况
目前据群友反馈已知:
- 魅族22无mbattery_charger目录生成,无法实时计算相应百分比
- 魅族18在后续的版本中关闭了mbattery_log生成,疑似无效,老版本可能支持
- 最完美的支持版本至少可覆盖魅族20/21系机型(20inf需后续确认)
---
@@ -48,4 +56,5 @@ flutter pub get
flutter run
# Release APK
flutter build apk --release
flutter build apk --release --target-platform android-arm64
```
Binary file not shown.
+22 -17
View File
@@ -1,31 +1,36 @@
/// 容量提取工具
/// 支持两种日志格式:
/// 1. learned_cap21 系列):单位 µAh,除以 1000 得到 mAh
/// 2. remaining_cap20 系列):单位 mAh,直接使用(但 21 系列的 remaining_cap 也是 µAh,需判断
///
/// 🟢 1.4.5 优化:仅从 status=Full 的行中提取容量(充满状态下 BMS 最准确)
/// 🟢 优先级最高,不受 status 限制(BMS 可能在任意状态行更新此值
/// 2. remaining_cap20 系列):仅从 status=Full 行提取,单位智能识别(µAh/mAh)
class CapacityExtractor {
static int? extractCapacity(List<String> lines) {
// 🟢 只保留包含 tbat= 且 status=Full 的行
final fullLines = lines.where((line) {
return line.contains('tbat=') && line.contains('status=Full');
}).toList();
final validLines = lines.where((line) => line.contains('tbat=')).toList();
if (validLines.isEmpty) return null;
if (fullLines.isEmpty) {
// 今天没有充满电的记录,返回 null 表示无有效数据
return null;
}
// 模式一:learned_cap21 系列)
// ============================================================
// 🟢 第一优先级:learned_cap(21 系列专属)
// 不限制 status,在所有有效行中搜索,取最新的一条
// ============================================================
final learnedReg = RegExp(r'learned_cap=(\d+)');
for (String line in fullLines.reversed) {
for (String line in validLines.reversed) {
final match = learnedReg.firstMatch(line);
if (match != null) {
return int.parse(match.group(1)!) ~/ 1000;
final value = int.parse(match.group(1)!);
// learned_cap 单位固定为 µAh,直接除以 1000 转 mAh
return value ~/ 1000;
}
}
// 模式二:remaining_cap 最大值(20 系列,或 21 系列回退)
// ============================================================
// 🟢 第二优先级:remaining_cap20 系列回退方案)
// 仅从 status=Full 行提取(充满状态下 BMS 最准确)
// ============================================================
final fullLines = validLines
.where((line) => line.contains('status=Full'))
.toList();
if (fullLines.isEmpty) return null;
final remainingReg = RegExp(r'remaining_cap=(\d+)');
int? maxRemaining;
for (String line in fullLines) {
@@ -39,7 +44,7 @@ class CapacityExtractor {
}
if (maxRemaining == null) return null;
// 🟢 判断单位:如果数值大于 100000(约 100 mAh),则认为是 µAh需除以 1000
// 🟢 智能单位识别:如果数值大于 100000(约 100 mAh),视为 µAh 需除以 1000
if (maxRemaining > 100000) {
return maxRemaining ~/ 1000;
} else {
+3 -2
View File
@@ -38,8 +38,9 @@ class ChargeParser {
final result = <Map<String, dynamic>>[];
for (String line in lines) {
final timestamp = TimeUtils.parseLogTimestamp(line);
if (!TimeUtils.isLogTimestampValid(timestamp, chargingStartTime))
if (!TimeUtils.isLogTimestampValid(timestamp, chargingStartTime)) {
continue;
}
final isUsb =
line.contains('chg_usb') &&
@@ -101,7 +102,7 @@ class ChargeParser {
return ParseResult(
isWireless: false,
chargeType: chargeType,
power: (vbus * ibus) / 1000000000.0,
power: (vbus * ibus) / 1000000000000.0,
volt: vbus / 1000000.0,
curr: ibus / 1000000.0,
wiredLevel: chargeType == 'PPS' ? level : null,
+37 -2
View File
@@ -5,7 +5,6 @@ import 'services/saf_storage_service.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 🟢 初始化 SAF 服务
await SafStorageService().init();
runApp(const MyApp());
@@ -19,9 +18,45 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: '电池健康度',
theme: ThemeData(
// 🟢 中文用 HarmonyOS Sans SC
fontFamily: 'HarmonyOS_Sans_SC',
// 🟢 数字回退到 FlymeFont
fontFamilyFallback: const ['Flyme'],
// 🟢 统一文字颜色为黑色
colorScheme: ColorScheme.fromSeed(
seedColor: const Color.fromARGB(255, 255, 255, 255),
seedColor: const Color(0xFFFFFFFF),
).copyWith(onSurface: Colors.black),
textTheme: const TextTheme(
// 大标题/数字(健康度、容量等)
displayMedium: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontFamilyFallback: ['Flyme'],
color: Colors.black,
),
// 标题(如“容量百分比变动趋势”)
headlineMedium: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontFamilyFallback: ['Flyme'],
color: Colors.black,
),
// 正文(电压、温度、循环次数等)
bodyMedium: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontFamilyFallback: ['Flyme'],
color: Colors.black,
),
// 小字(日期、辅助信息)
bodySmall: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontFamilyFallback: ['Flyme'],
color: Colors.black87,
),
// 数字专用(大号数字,如健康度百分比)
displayLarge: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontFamilyFallback: ['Flyme'],
color: Colors.black,
),
),
useMaterial3: true,
),
+36 -24
View File
@@ -2,9 +2,7 @@ import 'dart:async';
import 'dart:developer' as dev;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
// 检查这些导入是否正确
import '../models/device_matching.dart'; // ✅ 存在
@@ -322,10 +320,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
// ---------- 读取当前数据 ----------
Future<void> readBatteryCapacity() async {
dev.log(
'🔵 ========== readBatteryCapacity 开始 ==========',
name: 'BatteryHealth',
);
dev.log('🔴🔴🔴 readBatteryCapacity 被调用了 🔴🔴🔴', name: 'BatteryHealth');
_safState = await _safService.getPermissionState();
dev.log('🔵 SAF状态: $_safState', name: 'BatteryHealth');
@@ -354,6 +349,10 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
_currentCap = recent.first['capacity'].toDouble();
_maxVolt = recent.first['volt_max'] ?? 0;
_minVolt = recent.first['volt_min'] ?? 0;
// 🟢 数据库目前不存温度,后续升级可扩展,暂时保留为 0
_maxTemp = 0;
_minTemp = 0;
_cycleCount = 0;
_hasData = true;
});
await _updateTrendChart();
@@ -380,20 +379,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
return;
}
// 使用 CapacityExtractor 提取容量
final cap = CapacityExtractor.extractCapacity(lines);
if (cap == null) {
dev.log(
'🔵 未找到容量数据(learned_cap 或 remaining_cap',
name: 'BatteryHealth',
);
setState(() => _hasData = false);
_chargeAnimationController.reset();
_updateChargeState();
return;
}
// 提取最后一条有效数据用于显示
// 🟢 提取所有有效行(包含 tbat=
final validLines = lines.where((line) => line.contains('tbat=')).toList();
if (validLines.isEmpty) {
dev.log('🔵 无有效数据行', name: 'BatteryHealth');
@@ -403,6 +389,8 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
return;
}
// 🟢 1.4.7 核心改动:字段提取与容量提取解耦
// 无论 cap 是否为 null,都提取常规字段
final lastLine = validLines.last;
final cycle = _extractCycle(lastLine);
final temp = _extractTemp(lastLine);
@@ -411,12 +399,34 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
final (maxVolt, minVolt) = _extractVoltExtremes(validLines);
dev.log(
'🔵 解析结果: cap=$cap, cycle=$cycle, temp=$temp, volt=$volt',
'🔵 字段提取: cycle=$cycle, temp=$temp, volt=$volt',
name: 'BatteryHealth',
);
// 🟢 容量提取(可能为 null)
final cap = CapacityExtractor.extractCapacity(lines);
int? finalCap;
if (cap != null) {
// ✅ 今日有充满记录,直接使用
finalCap = cap;
dev.log('🔵 从日志提取容量: $cap', name: 'BatteryHealth');
} else {
// ⚠️ 今日无充满记录,尝试从数据库复制前一天容量
dev.log('🔵 今日无充满记录,尝试复制前一天容量', name: 'BatteryHealth');
final recent = await _dbService.queryRecentData(1);
if (recent.isNotEmpty) {
finalCap = recent.first['capacity'] as int;
dev.log('🔵 复制前一天容量: $finalCap', name: 'BatteryHealth');
} else {
finalCap = null;
dev.log('🔵 无历史数据可复制', name: 'BatteryHealth');
}
}
// 🟢 一次性 setState 更新所有字段
setState(() {
_currentCap = cap.toDouble();
_currentCap = (finalCap ?? _currentCap).toDouble();
_cycleCount = cycle;
_batteryTemp = temp;
_batteryVolt = volt;
@@ -603,7 +613,8 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
if (_isWireless) {
return ChargeUtils.getDisplayPowerWireless(_chargePower);
} else {
return ChargeUtils.getDisplayPowerWired(
// 🟢 1.5.0 改用新格式:实际/标定
return ChargeUtils.getMainDisplayPowerWired(
_chargePower,
_wiredLevel,
_chargeType,
@@ -620,7 +631,8 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
statusBarColor: Colors.white,
// 🟢 1.5.0 统一状态栏颜色
statusBarColor: Color.fromRGBO(157, 212, 237, 0.1),
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.dark,
),
+53 -6
View File
@@ -1,6 +1,7 @@
import '../constants/charge_maps.dart';
class ChargeUtils {
// ============ 无线充电(保持不变) ============
static String getDisplayPowerWireless(double power) {
if (power == 0) return '读取中...';
const List<int> levels = [5, 7, 15, 27, 40, 50, 66];
@@ -12,21 +13,17 @@ class ChargeUtils {
return '${matchedLevel}W';
}
// ============ 原有有线逻辑(保留兼容,但主界面不再直接调用) ============
static String getDisplayPowerWired(
double power,
int? wiredLevel,
String chargeType,
) {
// USB 慢充锁定 7.5W
if (chargeType == "SDP") return "≈7.5W";
// 🟢 优先使用 wiredLevel 精确匹配
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
double p = ChargeMaps.wiredPower[wiredLevel]!;
if (p > 0) return '${p.toInt()}W';
}
// 🟢 匹配阈值收窄到 ±3W,减少跳变
double best = 0;
for (var entry in ChargeMaps.wiredPower.entries) {
if (entry.value <= power + 3 && entry.value > best) {
@@ -37,11 +34,61 @@ class ChargeUtils {
return best > 0 ? '${best.toInt()}W' : '${power.round()}W';
}
// ============ 🟢 1.5.0 新增:主界面显示(实际/标定) ============
/// 示例:≈30w/65w
static String getMainDisplayPowerWired(
double power,
int? wiredLevel,
String chargeType,
) {
// USB 慢充锁定 7.5W
if (chargeType == "SDP") return "≈7.5w";
if (power == 0) return "读取中...";
final actual = power.round();
// 有档位且能查到标定值
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
final requested = ChargeMaps.wiredPower[wiredLevel]!.round();
return "${actual}w/${requested}w";
}
// 无档位信息,仅显示实际功率
return "${actual}w";
}
// ============ 🟢 1.5.0 新增:二级页面标定档位显示 ============
/// 示例:≈80w/L-10
static String getDetailRequestedPowerWired(
double power,
int? wiredLevel,
String chargeType,
) {
if (chargeType == "SDP") return "≈7.5w";
if (power == 0) return "读取中...";
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
final requested = ChargeMaps.wiredPower[wiredLevel]!.round();
return "${requested}w/L-$wiredLevel";
}
return "${power.round()}w";
}
// ============ 🟢 1.5.0 新增:二级页面实际功率显示 ============
static String getDetailActualPowerWired(double power, String chargeType) {
if (chargeType == "SDP") return "≈7.5w";
if (power == 0) return "读取中...";
return "${power.round()}w";
}
// ============ 充电类型标签(保持不变) ============
static String getChargeTypeLabel(bool isWireless, String chargeType) {
if (isWireless) {
return chargeType == "无线" ? "无线" : chargeType;
}
// 🟢 空类型显示"识别中...",比"等待log信息"更友好
if (chargeType.isEmpty) {
return "识别中...";
}
-2
View File
@@ -1,5 +1,3 @@
import 'dart:developer' as dev;
class TimeUtils {
/// 解析日志行中的时间戳,强制解析为 UTC
static DateTime? parseLogTimestamp(String line) {
+87 -28
View File
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
/// 电池信息面板(电压 + 温度 + 极值)
class BatteryInfoPanel extends StatelessWidget {
final double batteryVolt;
final double batteryTemp;
@@ -37,21 +36,45 @@ class BatteryInfoPanel extends StatelessWidget {
const SizedBox(height: 8),
Row(
children: [
Text(
'${maxVolt.toStringAsFixed(3)}V',
style: const TextStyle(
color: Colors.red,
fontSize: 14,
fontWeight: FontWeight.w500,
RichText(
text: TextSpan(
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.red,
),
children: [
const TextSpan(
text: '',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
color: Colors.red,
),
),
TextSpan(text: '${maxVolt.toStringAsFixed(3)}V'),
],
),
),
const SizedBox(width: 12),
Text(
'${minVolt.toStringAsFixed(3)}V',
style: const TextStyle(
color: Colors.blue,
fontSize: 14,
fontWeight: FontWeight.w500,
RichText(
text: TextSpan(
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.blue,
),
children: [
const TextSpan(
text: '',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
color: Colors.blue,
),
),
TextSpan(text: '${minVolt.toStringAsFixed(3)}V'),
],
),
),
],
@@ -66,26 +89,50 @@ class BatteryInfoPanel extends StatelessWidget {
_buildInfoItem(
_buildIcon('temperature'),
'温度',
'${batteryTemp.toStringAsFixed(0)}°C',
'${batteryTemp.toStringAsFixed(0)}',
),
const SizedBox(height: 8),
Row(
children: [
Text(
'${maxTemp.toStringAsFixed(0)}°C',
style: const TextStyle(
color: Colors.red,
fontSize: 14,
fontWeight: FontWeight.w500,
RichText(
text: TextSpan(
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.red,
),
children: [
const TextSpan(
text: '',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
color: Colors.red,
),
),
TextSpan(text: '${maxTemp.toStringAsFixed(0)}'),
],
),
),
const SizedBox(width: 12),
Text(
'${minTemp.toStringAsFixed(0)}°C',
style: const TextStyle(
color: Colors.blue,
fontSize: 14,
fontWeight: FontWeight.w500,
RichText(
text: TextSpan(
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.blue,
),
children: [
const TextSpan(
text: '',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
color: Colors.blue,
),
),
TextSpan(text: '${minTemp.toStringAsFixed(0)}'),
],
),
),
],
@@ -123,11 +170,23 @@ class BatteryInfoPanel extends StatelessWidget {
children: [
icon,
const SizedBox(width: 6),
Text(label, style: const TextStyle(fontSize: 14, color: Colors.grey)),
Text(
label,
style: const TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 14,
color: Colors.grey,
),
),
const SizedBox(width: 6),
Text(
value,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
style: const TextStyle(
fontFamily: 'Flyme',
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
],
);
+50 -36
View File
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
/// 电池健康度摘要组件(健康度 + cycles + mAh
class BatterySummary extends StatelessWidget {
final double healthPercent;
final int cycleCount;
@@ -17,6 +16,8 @@ class BatterySummary extends StatelessWidget {
@override
Widget build(BuildContext context) {
final bool isLowHealth = healthPercent < 70;
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
@@ -28,20 +29,22 @@ class BatterySummary extends StatelessWidget {
Text(
healthPercent.toStringAsFixed(1),
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 40,
fontWeight: FontWeight.w500,
height: 1.0,
color: healthPercent < 70 ? Colors.red : Colors.black,
color: isLowHealth ? Colors.red : Colors.black,
),
),
const SizedBox(width: 2),
Text(
'%',
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 20,
fontWeight: FontWeight.w300,
height: 1.0,
color: healthPercent < 70 ? Colors.red : Colors.grey.shade600,
color: isLowHealth ? Colors.red : Colors.grey.shade600,
),
),
],
@@ -51,46 +54,57 @@ class BatterySummary extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'$cycleCount cycles', // ✅ 修正:去掉下划线,使用 cycleCount
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
height: 1.2,
),
),
const SizedBox(height: 4),
Text.rich(
TextSpan(
RichText(
text: TextSpan(
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 16,
fontWeight: FontWeight.w500,
height: 1.2,
color: Colors.black,
),
children: [
TextSpan(text: '$cycleCount'),
TextSpan(
text: currentCap.toStringAsFixed(0),
text: ' cycles',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w300,
),
),
TextSpan(
text: ' / ',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w300,
color: Colors.grey.shade500,
),
),
TextSpan(
text: '${designCap}mAh',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w300,
fontFamily: 'HarmonyOS_Sans_SC',
color: Colors.black,
),
),
],
),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w300,
height: 1.0,
),
const SizedBox(height: 4),
RichText(
text: TextSpan(
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 20,
fontWeight: FontWeight.w300,
height: 1.0,
color: const Color(0xFF5F5F5F),
),
children: [
TextSpan(text: currentCap.toStringAsFixed(0)),
TextSpan(
text: ' / ',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
color: const Color(0xFF5F5F5F).withValues(alpha: 0.5),
),
),
TextSpan(text: designCap.toString()),
TextSpan(
text: ' mAh',
style: const TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 16,
fontWeight: FontWeight.w500,
color: Color(0xFF5F5F5F),
),
),
],
),
),
],
+114 -43
View File
@@ -1,7 +1,7 @@
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;
@@ -11,22 +11,14 @@ class ChargeDetailPage extends StatelessWidget {
final int? wiredLevel;
const ChargeDetailPage({
Key? key,
super.key,
required this.chargeType,
required this.isWireless,
required this.power,
required this.volt,
required this.curr,
this.wiredLevel,
}) : super(key: key);
String _getDisplayPower() {
if (isWireless) {
return ChargeUtils.getDisplayPowerWireless(power);
} else {
return ChargeUtils.getDisplayPowerWired(power, wiredLevel, chargeType);
}
}
});
String _getProtocolDisplay() {
if (isWireless) return '无线充电($chargeType';
@@ -35,47 +27,84 @@ class ChargeDetailPage extends StatelessWidget {
return chargeType;
}
String _getRequestedDisplay() {
return ChargeUtils.getDetailRequestedPowerWired(
power,
wiredLevel,
chargeType,
);
}
String _getActualDisplay() {
return ChargeUtils.getDetailActualPowerWired(power, chargeType);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('充电详情'),
backgroundColor: const Color.fromARGB(0, 255, 255, 255),
elevation: 0,
foregroundColor: Colors.black,
iconTheme: const IconThemeData(color: Colors.black),
return AnnotatedRegion<SystemUiOverlayStyle>(
value: const SystemUiOverlayStyle(
statusBarColor: Color.fromRGBO(157, 212, 237, 0.1),
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.dark,
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildDetailRow('协议', _getProtocolDisplay()),
const Divider(),
_buildDetailRow('功率', _getDisplayPower()),
const Divider(),
_buildDetailRow('电压', '${volt.toStringAsFixed(2)}V'),
const Divider(),
_buildDetailRow('电流', '${curr.toStringAsFixed(2)}A'),
const Divider(),
if (!isWireless && wiredLevel != null)
_buildDetailRow('档位', '$wiredLevel'),
if (!isWireless && wiredLevel == null) _buildDetailRow('档位', '自动'),
if (isWireless) _buildDetailRow('类型', '无线'),
const Spacer(),
Center(
child: Text(
'数据来自 BMS 实时日志',
style: TextStyle(fontSize: 12, color: Colors.grey.shade500),
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 _buildDetailRow(String label, String value) {
/// 纯文本行(协议、功率、档位等)
Widget _buildTextRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6.0),
child: Row(
@@ -84,6 +113,7 @@ class ChargeDetailPage extends StatelessWidget {
Text(
label,
style: const TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.grey,
@@ -92,6 +122,7 @@ class ChargeDetailPage extends StatelessWidget {
Text(
value,
style: const TextStyle(
fontFamily: 'HarmonyOS_Sans_SC', // 复杂字符串保持 Harmony
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.black87,
@@ -101,4 +132,44 @@ class ChargeDetailPage extends StatelessWidget {
),
);
}
/// 数值行(电压/电流,数字用 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'),
),
],
),
),
],
),
);
}
}
+3 -1
View File
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
/// 充电入口行(显示充电状态 + 点击进入详情)
class ChargeEntry extends StatelessWidget {
final String summary;
final bool isCharging;
@@ -23,6 +22,7 @@ class ChargeEntry extends StatelessWidget {
Text(
summary,
style: const TextStyle(
fontFamily: 'HarmonyOS_Sans_SC', // 🟢 混合文本用 Harmony
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.black87,
@@ -33,6 +33,7 @@ class ChargeEntry extends StatelessWidget {
Text(
'充电信息',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.grey.shade700,
@@ -42,6 +43,7 @@ class ChargeEntry extends StatelessWidget {
Text(
'>',
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.grey.shade700,
+14 -2
View File
@@ -50,7 +50,11 @@ class TrendChart extends StatelessWidget {
children: [
const Text(
'容量百分比变动趋势(近15天)',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 8),
Row(
@@ -64,6 +68,7 @@ class TrendChart extends StatelessWidget {
Text(
'100',
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 10,
color: Colors.grey,
height: 1.0,
@@ -72,6 +77,7 @@ class TrendChart extends StatelessWidget {
Text(
'70',
style: TextStyle(
fontFamily: 'Flyme',
fontSize: 10,
color: Colors.grey,
height: 1.0,
@@ -139,6 +145,7 @@ class TrendChart extends StatelessWidget {
child: Text(
sevenDaysAgoDate,
style: const TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 9,
color: Colors.grey,
height: 1.0,
@@ -152,6 +159,7 @@ class TrendChart extends StatelessWidget {
child: Text(
todayDate,
style: const TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 9,
color: Colors.black,
height: 1.0,
@@ -172,7 +180,11 @@ class TrendChart extends StatelessWidget {
padding: EdgeInsets.only(top: 8.0),
child: Text(
'暂无历史数据,请点击刷新按钮更新',
style: TextStyle(fontSize: 12, color: Colors.grey),
style: TextStyle(
fontFamily: 'HarmonyOS_Sans_SC',
fontSize: 12,
color: Colors.grey,
),
),
),
],
+4 -1
View File
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.4.0
version: 1.5.2
environment:
sdk: ^3.9.2
@@ -75,6 +75,9 @@ flutter:
weight: 400
- asset: assets/fonts/HarmonyOS_Sans_SC_Medium.ttf
weight: 500
- family: Flyme
fonts:
- asset: assets/fonts/flymeFont.ttf
assets:
- assets/icons/