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 36 additions and 28 deletions
+1 -1
View File
@@ -35,7 +35,7 @@
- Flutter SDK: ^3.9.2 - Flutter SDK: ^3.9.2
- Android: 8.0+ (API 26+) - 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 'dart:developer' as dev;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:device_info_plus/device_info_plus.dart'; import 'package:device_info_plus/device_info_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
// 检查这些导入是否正确 // 检查这些导入是否正确
import '../models/device_matching.dart'; // ✅ 存在 import '../models/device_matching.dart'; // ✅ 存在
@@ -322,10 +320,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
// ---------- 读取当前数据 ---------- // ---------- 读取当前数据 ----------
Future<void> readBatteryCapacity() async { Future<void> readBatteryCapacity() async {
dev.log( dev.log('🔴🔴🔴 readBatteryCapacity 被调用了 🔴🔴🔴', name: 'BatteryHealth');
'🔵 ========== readBatteryCapacity 开始 ==========',
name: 'BatteryHealth',
);
_safState = await _safService.getPermissionState(); _safState = await _safService.getPermissionState();
dev.log('🔵 SAF状态: $_safState', name: 'BatteryHealth'); dev.log('🔵 SAF状态: $_safState', name: 'BatteryHealth');
@@ -354,6 +349,10 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
_currentCap = recent.first['capacity'].toDouble(); _currentCap = recent.first['capacity'].toDouble();
_maxVolt = recent.first['volt_max'] ?? 0; _maxVolt = recent.first['volt_max'] ?? 0;
_minVolt = recent.first['volt_min'] ?? 0; _minVolt = recent.first['volt_min'] ?? 0;
// 🟢 数据库目前不存温度,后续升级可扩展,暂时保留为 0
_maxTemp = 0;
_minTemp = 0;
_cycleCount = 0;
_hasData = true; _hasData = true;
}); });
await _updateTrendChart(); await _updateTrendChart();
@@ -380,20 +379,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
return; return;
} }
// 使用 CapacityExtractor 提取容量 // 🟢 提取所有有效行(包含 tbat=
final cap = CapacityExtractor.extractCapacity(lines);
if (cap == null) {
dev.log(
'🔵 未找到容量数据(learned_cap 或 remaining_cap',
name: 'BatteryHealth',
);
setState(() => _hasData = false);
_chargeAnimationController.reset();
_updateChargeState();
return;
}
// 提取最后一条有效数据用于显示
final validLines = lines.where((line) => line.contains('tbat=')).toList(); final validLines = lines.where((line) => line.contains('tbat=')).toList();
if (validLines.isEmpty) { if (validLines.isEmpty) {
dev.log('🔵 无有效数据行', name: 'BatteryHealth'); dev.log('🔵 无有效数据行', name: 'BatteryHealth');
@@ -403,6 +389,8 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
return; return;
} }
// 🟢 1.4.7 核心改动:字段提取与容量提取解耦
// 无论 cap 是否为 null,都提取常规字段
final lastLine = validLines.last; final lastLine = validLines.last;
final cycle = _extractCycle(lastLine); final cycle = _extractCycle(lastLine);
final temp = _extractTemp(lastLine); final temp = _extractTemp(lastLine);
@@ -411,12 +399,34 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
final (maxVolt, minVolt) = _extractVoltExtremes(validLines); final (maxVolt, minVolt) = _extractVoltExtremes(validLines);
dev.log( dev.log(
'🔵 解析结果: cap=$cap, cycle=$cycle, temp=$temp, volt=$volt', '🔵 字段提取: cycle=$cycle, temp=$temp, volt=$volt',
name: 'BatteryHealth', 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(() { setState(() {
_currentCap = cap.toDouble(); _currentCap = (finalCap ?? _currentCap).toDouble();
_cycleCount = cycle; _cycleCount = cycle;
_batteryTemp = temp; _batteryTemp = temp;
_batteryVolt = volt; _batteryVolt = volt;
-2
View File
@@ -1,5 +1,3 @@
import 'dart:developer' as dev;
class TimeUtils { class TimeUtils {
/// 解析日志行中的时间戳,强制解析为 UTC /// 解析日志行中的时间戳,强制解析为 UTC
static DateTime? parseLogTimestamp(String line) { static DateTime? parseLogTimestamp(String line) {
+2 -2
View File
@@ -11,14 +11,14 @@ class ChargeDetailPage extends StatelessWidget {
final int? wiredLevel; final int? wiredLevel;
const ChargeDetailPage({ const ChargeDetailPage({
Key? key, super.key,
required this.chargeType, required this.chargeType,
required this.isWireless, required this.isWireless,
required this.power, required this.power,
required this.volt, required this.volt,
required this.curr, required this.curr,
this.wiredLevel, this.wiredLevel,
}) : super(key: key); });
String _getDisplayPower() { String _getDisplayPower() {
if (isWireless) { 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 # 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 # 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. # of the product and file versions while build-number is used as the build suffix.
version: 1.4.0 version: 1.4.7
environment: environment:
sdk: ^3.9.2 sdk: ^3.9.2