4 Commits

Author SHA1 Message Date
lxh2875931338 46f8dbc67e log信息来源补充 2026-07-06 19:05:37 +08:00
lxh2875931338 28824501dc 相应的版本更新 2026-07-06 18:57:42 +08:00
lxh2875931338 76bff59afc 部分自动优化 2026-07-06 18:29:49 +08:00
lxh2875931338 26aa931e06 更新一下readme 2026-07-05 23:55:56 +08:00
5 changed files with 37 additions and 28 deletions
+2 -1
View File
@@ -25,6 +25,7 @@
| 版本 | 主题 | 状态 |
| :--- | :--- | :--- |
| 1.4.0 | SAF 权限改造 | ✅ 已发布 |
| 1.4.5 | 魅族20系补充适配调整 | ✅ 已发布 |
| 1.5.0 | 功率计算优化 | 📋 规划中 |
| 2.0.0 | 数据看板扩展(月/季/年趋势) | 📋 远景 |
@@ -34,7 +35,7 @@
- Flutter SDK: ^3.9.2
- Android: 8.0+ (API 26+)
- 仅支持魅族手机(15 系列 ~ 25 系列)
- 仅支持魅族手机(15 系列 ~ 22 系列)
---
+32 -22
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;
-2
View File
@@ -1,5 +1,3 @@
import 'dart:developer' as dev;
class TimeUtils {
/// 解析日志行中的时间戳,强制解析为 UTC
static DateTime? parseLogTimestamp(String line) {
+2 -2
View File
@@ -11,14 +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) {
+1 -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.4.7
environment:
sdk: ^3.9.2