Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea2a40d2ae | ||
|
|
232e6468ee | ||
|
|
7be96656ac | ||
|
|
b4d8ba63f8 | ||
|
|
125fb969e4 | ||
|
|
8be4ff7e40 | ||
|
|
4829cd1da2 | ||
|
|
7989495521 | ||
|
|
1d033670f7 | ||
|
|
2512f88f30 |
@@ -1,88 +1,273 @@
|
||||
# MEIZU Battery Healthy
|
||||
|
||||
> 专机专配 · 仅针对魅族独家开发
|
||||
> **专机专配 · 仅针对魅族设备开发**
|
||||
>
|
||||
> 一款面向魅族手机的电池健康度与充电状态监测工具。
|
||||
|
||||
一个简洁的手机电池健康度监测工具<br>
|
||||
通过读取 BMS 日志(`/storage/emulated/0/mbattery_charger/`)直接获取电池真实数据<br>
|
||||
不依赖系统 API 估算。
|
||||
MEIZU Battery Healthy 是一款基于 Flutter 开发的 Android 电池监测工具,主要针对魅族设备及其 Flyme 系统进行适配。
|
||||
|
||||
---
|
||||
应用以设备生成的 BMS 充电日志为核心数据来源,结合 Android `BatteryManager` API,读取电池容量、电压、温度、循环次数及实时充电参数,并通过本地数据库积累历史数据。
|
||||
|
||||
## 功能
|
||||
与仅展示系统电量百分比的工具不同,本项目更关注**底层数据的读取、不同数据源的对照,以及电池状态的长期观测**。
|
||||
|
||||
- 读取 BMS 日志,解析 `learned_cap`、`cycle`、`tbat`、`vbat` 等关键字段
|
||||
- 显示电池健康度(当前容量 / 设计容量)
|
||||
- 显示循环次数、电压、温度(含当日极值)
|
||||
- 近 15 天容量百分比趋势柱状图
|
||||
- 实时充电状态识别(有线 / 无线、PPS / SDP / EPP)
|
||||
- 充电功率、电压、电流实时显示
|
||||
- 充电详情页(协议 / 功率 / 电压 / 电流 / 档位)
|
||||
## 功能特性
|
||||
|
||||
---
|
||||
### 🔋 日常健康观察
|
||||
|
||||
## 当前状态
|
||||
- **电池容量提取**:优先读取 `learned_cap`,部分机型回退至 `remaining_cap` 与 `status=Full` 的组合。
|
||||
- **健康度计算**:根据当前可用容量与机型设计容量计算健康度百分比。
|
||||
- **循环次数**:解析 BMS 日志中的 `cycle` 字段。
|
||||
- **电压监测**:显示当前电压及当日最高、最低电压。
|
||||
- **温度监测**:显示当前温度、当日最高温度、最低温度与平均温度。
|
||||
- **异常数据提示**:对容量低于 60%、高于 115% 等异常读数进行标记,并提示电压异常。
|
||||
|
||||
| 版本 | 主题 | 状态 |
|
||||
| :--- | :--- | :--- |
|
||||
| 1.5.0 | 功率计算优化 | ✅ 已发布 |
|
||||
| 1.5.2 | 部分场景字体替换 | ✅ 已发布 |
|
||||
| 1.6.0 | 更新日志独立页面 | ✅ 已发布 |
|
||||
| 1.7.0 | 关于页与紧急发布log文件数据反作弊能力 | ✅ 已发布 |
|
||||
| 1.8.0 | 适配夜间模式 | 📋近期开发 |
|
||||
| 2.0.0 | 数据看板月份显示扩展等系列更新 | 📋 远景 |
|
||||
| 3.0.0 | 搭配PC上位机记录充电信息等 | 📋 远景 |
|
||||
---
|
||||
### ⚡ 实时充电监控
|
||||
|
||||
## 环境要求
|
||||
- **充电状态识别**:识别有线充电、无线充电及 USB 相关状态。
|
||||
- **充电协议识别**:解析 PPS、SDP、EPP 等协议标识。
|
||||
- **充电档位解析**:将 BMS 日志中的 `L-n` 标定档位转换为对应的功率信息。
|
||||
- **双数据源监测**:
|
||||
- BMS 侧:读取充电器端电压、电流、功率及无线充电参数。
|
||||
- BatteryManager 侧:读取电池端电压、电流,并计算电池端功率。
|
||||
- **独立刷新策略**:BatteryManager 数据约每秒刷新一次;BMS 数据采用约 15 秒的轮询策略,实际更新还受到日志生成与落盘延迟影响。
|
||||
- **充电详情页**:分别展示 BMS 日志与 BatteryManager 数据,方便对照观察。
|
||||
|
||||
- Flutter SDK: ^3.9.2
|
||||
- Android: 8.0+ (API 26+)
|
||||
#### 主界面充电信息示例:
|
||||
|
||||
---
|
||||
`充电中 · PPS · 5.98W / 7.5W`
|
||||
|
||||
## 机型匹配情况
|
||||
- **PPS**:当前识别到的充电协议。
|
||||
- **5.98W**:由 Android `BatteryManager` API 获取电池端电流,并结合电压计算得到的当前功率,反映电池端的实时充电状态。
|
||||
- **7.5W**:由 BMS 日志解析得到的当前充电档位对应的标定功率,用于表示该档位的功率信息。
|
||||
|
||||
| 机型 | 系统版本 | 容量来源 | 设计容量 | 状态 |
|
||||
|---|---|---|---|---|
|
||||
| 魅族 22 | Flyme 12.x | 系统未生成 `mbattery_charger` 目录 | 5510 mAh | ❌ 不支持 |
|
||||
| 魅族 21 | Flyme 12.x | `learned_cap` | 4800 mAh | ✅ 与 21 Pro 同步获得支持 |
|
||||
| 魅族 21 Pro | Flyme 12.x | `learned_cap` | 5050 mAh | ✅ 初始支持 |
|
||||
| 魅族 21 Note | Flyme 12.x | `learned_cap` | 5500 mAh | ✅ 1.6.0 新增支持 |
|
||||
> 其中,电池端功率为实时计算值,充电档位功率为 BMS 提供的档位信息。两者的数据来源、更新频率与测量口径不同,不应直接视为同一测量点的实际功率与额定功率。
|
||||
|
||||
### 📈 历史数据与趋势
|
||||
|
||||
- 使用 SQLite 在本地持久化每日容量、电压极值及平均温度。
|
||||
- 支持全量日志扫描与历史数据入库。
|
||||
- 提供近 15 天电池容量百分比趋势柱状图。
|
||||
- 支持数据库版本管理与自动迁移,目前 v2 版本新增 `temp_avg` 字段。
|
||||
|
||||
### 🎨 主题与界面
|
||||
|
||||
- 支持浅色、深色及跟随系统三种主题模式。
|
||||
- 使用 Flutter `ThemeExtension` 统一管理深浅主题色板。
|
||||
- 首页、详情页、更新日志页及关于页适配深色模式。
|
||||
- 使用 SharedPreferences 持久化主题选择。
|
||||
- 针对中文与数字采用不同的字体显示策略。
|
||||
|
||||
## 机型兼容性
|
||||
|
||||
本项目采用**机型与 Flyme 版本联合适配**的策略。同一机型在不同系统版本下,可能存在日志格式变化、字段缺失或日志停止生成等情况。
|
||||
|
||||
以下为当前已知的适配情况。
|
||||
|
||||
| 机型 | 系统版本 | 容量数据来源 | 设计容量 | 状态 |
|
||||
|---|---|---|---:|---|
|
||||
| 魅族 22 | Flyme 12.x | 系统未生成日志目录 | 5510 mAh | ❌ 不支持 |
|
||||
| 魅族 21 | Flyme 12.x | `learned_cap` | 4800 mAh | ✅ 支持 |
|
||||
| 魅族 21 Pro | Flyme 12.x | `learned_cap` | 5050 mAh | ✅ 支持 |
|
||||
| 魅族 21 Note | Flyme 12.x | `learned_cap` | 5500 mAh | ✅ 支持 |
|
||||
| 魅族 21 Note | Flyme 10 / 11 | 日志格式异常 | — | ❌ 不支持 |
|
||||
| 魅族 20 | Flyme 12.x | `remaining_cap` + `status=Full` | 4700 mAh | ✅ 1.4.0 首次支持 |
|
||||
| 魅族 20 Pro | Flyme 12.x | `remaining_cap` + `status=Full` | 5000 mAh | ✅ 1.4.0 首次支持 |
|
||||
| 魅族 20 INFINITY | Flyme 10.x | `remaining_cap` + `status=Full` | 4800 mAh | ✅ 1.5.3 字段匹配 |
|
||||
| 魅族 18 / 18s / 18 Pro / 18s Pro / 18X | Flyme 9 | 日志停止生成 | 4000 / 4500 mAh | ❌ 无适配条件 |
|
||||
| 魅族 18 / 18s / 18 Pro / 18s Pro / 18X | Flyme 10 | 不再主动适配 | 4000 / 4500 mAh | ⚠️ 实验性支持 |
|
||||
| 魅族 17 / 17Pro | Flyme 8 / 9 / 10 | 等待群友提供字段信息 | 4500 / 4500mAh | ⚠️ 待验证 |
|
||||
| 魅族 16th / 16th Plus / 16X / 16s / 16sPro / 16Xs / 16T | Flyme 7 / 8 / 9 | 需回退原厂固件验证 | - | ⚠️ 若新版本无日志,则变为实验性支持,不主动适配 |
|
||||
| 魅族 20 | Flyme 12.x | `remaining_cap` + `status=Full` | 4700 mAh | ✅ 支持 |
|
||||
| 魅族 20 Pro | Flyme 12.x | `remaining_cap` + `status=Full` | 5000 mAh | ✅ 支持 |
|
||||
| 魅族 20 INFINITY | Flyme 10.x | `remaining_cap` + `status=Full` | 4800 mAh | ✅ 支持 |
|
||||
| 魅族 18 / 18s 系列 | Flyme 9 | 日志停止生成 | 4000 / 4500 mAh | ❌ 不支持 |
|
||||
| 魅族 18 / 18s 系列 | Flyme 10 | 待实机确认 | 4000 / 4500 mAh | ⚠️ 实验性支持 |
|
||||
| 魅族 17 / 17 Pro | Flyme 8 / 9 / 10 | 待收集日志样本 | 4500 mAh | ⚠️ 待验证 |
|
||||
| 魅族 16 系列 | Flyme 7 / 8 / 9 | 待验证 | — | ⚠️ 实验性支持 |
|
||||
|
||||
### 状态说明
|
||||
|
||||
| 状态 | 含义 |
|
||||
- ✅ **支持**:已通过实机验证,相关字段能够正常解析。
|
||||
- ⚠️ **实验性支持**:具备一定适配基础,但尚未完成充分的实机验证。
|
||||
- ⚠️ **待验证**:缺少足够的日志样本或实机测试结果。
|
||||
- ❌ **不支持**:当前已知环境下无法获取所需数据,或日志格式不满足解析要求。
|
||||
|
||||
### 兼容性说明
|
||||
|
||||
**Flyme 版本差异**
|
||||
|
||||
同一机型在不同 Flyme 版本下可能使用不同的日志格式或字段。请以具体机型和系统版本的实际测试结果为准。
|
||||
|
||||
**日志生成状态**
|
||||
|
||||
部分设备升级系统后可能不再生成新的 BMS 日志。即使日志目录仍然存在,也不代表其中的数据持续更新。
|
||||
|
||||
**设计容量**
|
||||
|
||||
设计容量用于计算健康度,并非由应用实时测量。计算结果会受到机型参数、底层容量字段含义及电池管理系统校准状态的影响。
|
||||
|
||||
**适配策略**
|
||||
|
||||
当前优先维护日志格式相对稳定、已完成实机验证的机型。旧机型及其他系统版本的适配将根据实际日志样本逐步推进。
|
||||
|
||||
## 数据来源与测量说明
|
||||
|
||||
本项目使用两套数据来源,分别承担底层日志分析与实时电池监测的职责。
|
||||
|
||||
### 1. BMS 日志:充电器端及设备充电状态
|
||||
|
||||
- **数据位置**:`/storage/emulated/0/mbattery_charger/`
|
||||
- **主要字段**:`learned_cap`、`remaining_cap`、`cycle`、`tbat`、`vbat`、`ibus`、`vbus`、`wls_volt`、`wls_curr` 等。
|
||||
- **主要用途**:容量提取、循环次数解析、充电协议识别、充电档位解析及充电器端参数展示。
|
||||
- **更新特征**:日志写入与落盘存在延迟,应用的轮询间隔不等于底层数据的实际更新频率。
|
||||
|
||||
BMS 日志的可用字段取决于设备及系统版本。不同机型不一定提供完全相同的数据。
|
||||
|
||||
### 2. BatteryManager:电池端实时监测
|
||||
|
||||
- **接口**:`BatteryManager.BATTERY_PROPERTY_CURRENT_NOW`
|
||||
- **主要用途**:获取电池端电流,并结合电压计算电池端功率。
|
||||
- **刷新策略**:应用侧约每秒轮询一次。
|
||||
- **数据特征**:电流读数的单位、符号及实际更新行为需要结合 Android 实现与设备厂商行为处理。
|
||||
|
||||
本项目会对电流极性进行归一化,使充电方向以正值显示。
|
||||
|
||||
需要注意,BatteryManager 提供的电流读数并不等同于充电器的输出电流。它反映的是电池端的电流状态,可能受到系统功耗、充电管理策略及电量计实现的影响。
|
||||
|
||||
### 3. 两套数据如何对照?
|
||||
|
||||
BMS 数据主要用于观察充电器端及充电协议相关信息,BatteryManager 数据主要用于观察电池端电流、电压与功率。
|
||||
|
||||
在采样时间接近、测量口径明确的情况下,两侧功率的差异可以帮助分析系统运行功耗与转换损耗。但由于日志延迟、采样时差及两侧测量边界不同,**功率差值只能作为参考,不能直接视为精确的系统功耗或充电转换损耗**。
|
||||
|
||||
### 4. 数据可信度与适用边界
|
||||
|
||||
- 健康度是根据可读取的容量字段与预设设计容量计算得到的结果,不等同于专业电池检测设备给出的容量测试结果。
|
||||
- 容量、电压与温度异常标记用于辅助识别可疑读数,不单独构成电池故障诊断。
|
||||
- 日志数据可能存在缺失、延迟、格式差异或历史记录不完整的情况。
|
||||
- 应用不会将尚未验证的机型适配能力视为已经得到实机确认。
|
||||
|
||||
## 技术架构
|
||||
|
||||
项目采用 Flutter 与 Kotlin 原生通道协作的结构。
|
||||
|
||||
```text
|
||||
MEIZU Battery Healthy
|
||||
│
|
||||
├── Flutter UI
|
||||
│ ├── 首页
|
||||
│ ├── 充电详情页
|
||||
│ ├── 历史趋势
|
||||
│ ├── 更新日志
|
||||
│ └── 关于页面
|
||||
│
|
||||
├── 业务逻辑层
|
||||
│ ├── ChargeParser
|
||||
│ ├── CapacityExtractor
|
||||
│ ├── BatteryDataService
|
||||
│ └── ChargeUtils
|
||||
│
|
||||
├── 服务层
|
||||
│ ├── SafStorageService
|
||||
│ ├── BatteryManagerService
|
||||
│ ├── DatabaseService
|
||||
│ └── ThemeService
|
||||
│
|
||||
└── Kotlin 原生层
|
||||
├── /saf
|
||||
├── /charge
|
||||
├── /charge_events
|
||||
├── /frame_rate
|
||||
└── BatteryManagerHelper
|
||||
```
|
||||
|
||||
### 主要技术组件
|
||||
|
||||
- **Flutter**:跨层 UI 与业务逻辑实现。
|
||||
- **Kotlin / Android 原生接口**:文件访问、BatteryManager 数据读取、充电插拔事件与刷新率控制。
|
||||
- **SQLite**:本地历史数据持久化及数据库迁移。
|
||||
- **SharedPreferences**:主题配置与授权相关状态的持久化。
|
||||
|
||||
日志访问通过 Android Storage Access Framework(SAF)授权机制管理。实际可读取的数据取决于用户授权状态及设备系统对相关文件的访问权限。
|
||||
|
||||
## 开发环境
|
||||
|
||||
| 组件 | 版本要求 |
|
||||
|---|---|
|
||||
| ✅ 完美支持 | 已通过实机验证,所有字段完整解析 |
|
||||
| ⚠️ 实验性支持 | 理论上可支持,但需要用户协助验证 |
|
||||
| ⚠️ 待验证 | 尚未收到实机日志反馈,待确认 |
|
||||
| ❌ 不支持 | 系统未生成 BMS 日志,或日志格式无法解析 |
|
||||
| Flutter SDK | `^3.9.2` |
|
||||
| Android | API 26+(Android 8.0+) |
|
||||
| Android Gradle Plugin | 9.0.0 |
|
||||
| Kotlin Gradle Plugin | 2.2.20 |
|
||||
| Gradle | 9.3.1 |
|
||||
|
||||
### 特别说明
|
||||
当前版本使用经过验证的构建工具组合。升级 AGP、KGP 或 Gradle 前,建议先完成构建兼容性验证。
|
||||
|
||||
- **Flyme 版本差异**:同一机型在不同 Flyme 版本下日志格式可能不同。例如 21 Note 在 Flyme 12.x 下可正常读取 `learned_cap`,但在 Flyme 10/11 下日志格式异常。
|
||||
- **日志停止生成**:部分机型在升级到新系统后(如 17/18 系升级到 Flyme 10),系统不再向 `mbattery_charger` 目录写入新日志,文件夹虽存在但停止更新。
|
||||
- **适配策略**:优先支持日志格式稳定的 Flyme 12.x 机型,旧版本系统暂不主动适配,若有用户长期停留在旧版本并愿意协助测试,可酌情增加支持。
|
||||
## 从源码构建
|
||||
|
||||
---
|
||||
### 1. 获取源码
|
||||
|
||||
## 如果需要基于此源代码构建
|
||||
```bash
|
||||
git clone https://git.whitetop.xyz/lxh2875931338/MEIZU-Battery-Healthy.git
|
||||
cd MEIZU-Battery-Healthy
|
||||
```
|
||||
|
||||
### 2. 安装依赖
|
||||
|
||||
```bash
|
||||
# 拉取依赖
|
||||
flutter pub get
|
||||
```
|
||||
|
||||
# Debug 版本
|
||||
### 3. 运行 Debug 版本
|
||||
|
||||
```bash
|
||||
flutter run --debug
|
||||
```
|
||||
|
||||
# Release APK
|
||||
### 4. 构建 Release APK
|
||||
|
||||
当前发布构建面向 ARM64 Android 设备:
|
||||
|
||||
```bash
|
||||
flutter build apk --release --target-platform android-arm64
|
||||
```
|
||||
|
||||
### 构建注意事项
|
||||
|
||||
- 修改 Kotlin 原生代码后,需要重新执行构建或运行流程;热重载不会重新编译原生代码。
|
||||
- Release 构建需要 `android/app/proguard-rules.pro`,项目已包含对应规则。
|
||||
- 不建议在未完成验证前随意升级 AGP、KGP 或 Gradle。
|
||||
- 实际构建结果还取决于本地 Android SDK、JDK 及依赖环境。
|
||||
|
||||
## 版本历史
|
||||
|
||||
| 版本 | 主要更新 | 状态 |
|
||||
|---|---|---|
|
||||
| 1.5.0 | 功率计算优化 | ✅ 已发布 |
|
||||
| 1.5.2 | 部分场景字体替换 | ✅ 已发布 |
|
||||
| 1.6.0 | 更新日志独立页面 | ✅ 已发布 |
|
||||
| 1.7.0 | 关于页、数据反作弊校验 | ✅ 已发布 |
|
||||
| 1.7.1 | 平均温度显示、数据库 v2 迁移 | ✅ 已发布 |
|
||||
| 1.8.0 | 夜间模式、主题系统重构 | ✅ 已发布 |
|
||||
| 1.9.0 | BatteryManager 实时数据接入 | ✅ 已发布 |
|
||||
|
||||
### 后续规划
|
||||
|
||||
| 版本 | 规划内容 | 状态 |
|
||||
|---|---|---|
|
||||
| 2.0.0 | 数据看板月份扩展、充电曲线 | 📋 开发中 |
|
||||
| 3.0.0 | PC 上位机充电信息记录 | 📋 远景规划 |
|
||||
|
||||
以上规划不代表相关功能已经包含在当前发布版本中,实际进度以仓库更新为准。
|
||||
|
||||
## 反馈与机型适配
|
||||
|
||||
项目优先关注真实设备上的数据可用性与日志格式差异。
|
||||
|
||||
如果你希望协助适配新机型,欢迎提交 Issue,并尽可能提供以下信息:
|
||||
|
||||
- 手机型号。
|
||||
- Flyme 系统版本。
|
||||
- BMS 日志是否持续生成。
|
||||
- 容量字段及充电相关字段的可用情况。
|
||||
- 对应的异常现象与复现步骤。
|
||||
|
||||
日志样本可能包含设备运行信息。提交前请检查并移除个人信息、设备标识及其他不希望公开的内容。
|
||||
|
||||
**源码仓库:**
|
||||
|
||||
[MEIZU Battery Healthy](https://git.whitetop.xyz/lxh2875931338/MEIZU-Battery-Healthy)
|
||||
|
||||
> 本项目专注于魅族设备的电池状态观测与数据分析,不保证所有魅族机型或所有 Flyme 版本均可使用。监测结果仅供参考,不构成电池故障诊断或维修依据。
|
||||
|
||||
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
# ============ Flutter 核心 ============
|
||||
-keep class io.flutter.** { *; }
|
||||
-keep class io.flutter.plugins.** { *; }
|
||||
-keep class io.flutter.plugin.** { *; }
|
||||
-keep class io.flutter.util.** { *; }
|
||||
-keep class io.flutter.view.** { *; }
|
||||
-keep class io.flutter.embedding.** { *; }
|
||||
|
||||
# 保留 Flutter 的 JNI 调用类
|
||||
-keep class io.flutter.embedding.engine.FlutterJNI { *; }
|
||||
-dontwarn io.flutter.embedding.**
|
||||
|
||||
# ============ Kotlin ============
|
||||
-keep class kotlin.** { *; }
|
||||
-keep class kotlin.Metadata { *; }
|
||||
-dontwarn kotlin.**
|
||||
-keepclassmembers class **$WhenMappings {
|
||||
<fields>;
|
||||
}
|
||||
-keepclassmembers class kotlin.Metadata {
|
||||
public <methods>;
|
||||
}
|
||||
|
||||
# ============ sqflite / SQLite ============
|
||||
-keep class com.tekartik.sqflite.** { *; }
|
||||
-dontwarn com.tekartik.sqflite.**
|
||||
|
||||
# ============ shared_preferences ============
|
||||
-keep class io.flutter.plugins.sharedpreferences.** { *; }
|
||||
|
||||
# ============ path_provider ============
|
||||
-keep class io.flutter.plugins.pathprovider.** { *; }
|
||||
|
||||
# ============ permission_handler ============
|
||||
-keep class com.baseflow.permissionhandler.** { *; }
|
||||
|
||||
# ============ url_launcher ============
|
||||
-keep class io.flutter.plugins.urllauncher.** { *; }
|
||||
|
||||
# ============ device_info_plus ============
|
||||
-keep class dev.fluttercommunity.plus.device_info.** { *; }
|
||||
|
||||
# ============ 你的原生通道(重要!) ============
|
||||
# 你的 MethodChannel / EventChannel 相关类需要保留
|
||||
-keep class com.lxh.battery_health.** { *; }
|
||||
|
||||
# ============ AndroidX 常见 ============
|
||||
-keep class androidx.lifecycle.** { *; }
|
||||
-dontwarn androidx.lifecycle.**
|
||||
|
||||
# ============ 保留 Parcelable / Serializable ============
|
||||
-keepclassmembers class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
-keepclassmembers class * implements java.io.Serializable {
|
||||
static final long serialVersionUID;
|
||||
private static final java.io.ObjectStreamField[] serialPersistentFields;
|
||||
private void writeObject(java.io.ObjectOutputStream);
|
||||
private void readObject(java.io.ObjectInputStream);
|
||||
java.lang.Object writeReplace();
|
||||
java.lang.Object readResolve();
|
||||
}
|
||||
|
||||
# ============ 异常堆栈保留(方便排查 release 崩溃) ============
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
-renamesourcefileattribute SourceFile
|
||||
-keepattributes Signature
|
||||
-keepattributes *Annotation*
|
||||
-keepattributes Exceptions
|
||||
-keepattributes InnerClasses
|
||||
-keepattributes EnclosingMethod
|
||||
|
||||
# ============ 移除日志(可选) ============
|
||||
# 如果你想在 release 里保留日志,注释掉下面这几行
|
||||
-assumenosideeffects class android.util.Log {
|
||||
public static *** v(...);
|
||||
public static *** d(...);
|
||||
public static *** i(...);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.lxh.battery_health
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.BatteryManager
|
||||
|
||||
class BatteryManagerHelper(private val context: Context) {
|
||||
|
||||
fun getBatteryData(): Map<String, Any?> {
|
||||
val bm = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager
|
||||
|
||||
// 电流(µA)。部分机型充电为负、放电为正,部分相反
|
||||
val rawCurrentUa = bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_NOW)
|
||||
|
||||
// 电压 / 状态从 ACTION_BATTERY_CHANGED 广播里拿(比 BATTERY_PROPERTY_VOLTAGE 兼容性好)
|
||||
val intent = context.registerReceiver(
|
||||
null,
|
||||
IntentFilter(Intent.ACTION_BATTERY_CHANGED)
|
||||
)
|
||||
val voltageMv = intent?.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1) ?: -1
|
||||
val status = intent?.getIntExtra(BatteryManager.EXTRA_STATUS, -1) ?: -1
|
||||
val plugged = intent?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) ?: -1
|
||||
val temperatureTenth = intent?.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1) ?: -1
|
||||
|
||||
val isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
|
||||
status == BatteryManager.BATTERY_STATUS_FULL
|
||||
|
||||
// 符号规约:充电为正
|
||||
val normalizedUa = when {
|
||||
rawCurrentUa == Int.MIN_VALUE -> 0
|
||||
isCharging && rawCurrentUa < 0 -> -rawCurrentUa
|
||||
!isCharging && rawCurrentUa > 0 -> -rawCurrentUa
|
||||
else -> rawCurrentUa
|
||||
}
|
||||
|
||||
// 功率 W = V × A = (mV / 1000) × (µA / 1_000_000)
|
||||
val powerW = if (voltageMv > 0 && normalizedUa != 0) {
|
||||
(voltageMv / 1000.0) * (normalizedUa / 1_000_000.0)
|
||||
} else 0.0
|
||||
|
||||
return mapOf(
|
||||
"voltageMv" to voltageMv,
|
||||
"currentUa" to normalizedUa,
|
||||
"powerW" to powerW,
|
||||
"temperatureC" to if (temperatureTenth > 0) temperatureTenth / 10.0 else 0.0,
|
||||
"plugged" to plugged, // 0=未插, 1=AC, 2=USB, 4=WIRELESS
|
||||
"isCharging" to isCharging,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -255,26 +255,35 @@ private fun clearRefreshRate() {
|
||||
|
||||
// 充电状态通道
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHARGE_CHANNEL)
|
||||
.setMethodCallHandler { call, result ->
|
||||
if (call.method == "getChargeState") {
|
||||
val isCharging = getBatteryStatus()
|
||||
val chargeType = if (isCharging) {
|
||||
val batteryIntent = registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
|
||||
val plug = batteryIntent?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) ?: -1
|
||||
when (plug) {
|
||||
BatteryManager.BATTERY_PLUGGED_AC -> "AC"
|
||||
BatteryManager.BATTERY_PLUGGED_USB -> "USB"
|
||||
BatteryManager.BATTERY_PLUGGED_WIRELESS -> "WIRELESS"
|
||||
else -> "UNKNOWN"
|
||||
}
|
||||
} else {
|
||||
"NONE"
|
||||
.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"getChargeState" -> {
|
||||
val isCharging = getBatteryStatus()
|
||||
val chargeType = if (isCharging) {
|
||||
val batteryIntent = registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
|
||||
val plug = batteryIntent?.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) ?: -1
|
||||
when (plug) {
|
||||
BatteryManager.BATTERY_PLUGGED_AC -> "AC"
|
||||
BatteryManager.BATTERY_PLUGGED_USB -> "USB"
|
||||
BatteryManager.BATTERY_PLUGGED_WIRELESS -> "WIRELESS"
|
||||
else -> "UNKNOWN"
|
||||
}
|
||||
result.success(mapOf("isCharging" to isCharging, "chargeType" to chargeType))
|
||||
} else {
|
||||
result.notImplemented()
|
||||
"NONE"
|
||||
}
|
||||
result.success(mapOf("isCharging" to isCharging, "chargeType" to chargeType))
|
||||
}
|
||||
// 🆕 新增分支
|
||||
"getBatteryManagerData" -> {
|
||||
try {
|
||||
result.success(BatteryManagerHelper(applicationContext).getBatteryData())
|
||||
} catch (e: Exception) {
|
||||
result.error("BM_ERROR", e.message, null)
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
||||
// SAF 通道
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, SAF_CHANNEL)
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,3 +1,70 @@
|
||||
## [1.9.0] - 2026-10-11
|
||||
|
||||
### ✨ 新增功能
|
||||
|
||||
- **BatteryManager 实时数据接入**
|
||||
- 新增原生 `BatteryManagerHelper`,通过 Android 官方 API 读取电池端真实功率
|
||||
- 主界面充电行改为显示电池端实时功率(1 秒刷新),反映电池实际吸收的能量
|
||||
- 充电详情页拆分为两个数据源分区:
|
||||
- **BMS 日志**:协议、标定档位、实际功率、电压、电流(原有)
|
||||
- **BatteryManager(电池端)**:电池端电压、电流、功率(新增)
|
||||
- 与专业功率计(PowerZ)实测数据一致,误差在 0.02W 以内
|
||||
|
||||
### 🎨 体验优化
|
||||
|
||||
- **充电行显示格式调整**
|
||||
- 有线充电:`充电中 · PPS · 5.98W / 7.5W`(实际功率 / 标定档位)
|
||||
- 无线充电:`充电中 · 无线 · 12.3W`
|
||||
- USB 慢充:`充电中 · USB · 2.1W`
|
||||
- 瓦特单位统一为大写 `W`
|
||||
- 7.5W 等带小数的档位保留一位小数,其余整数值去掉 `.0`
|
||||
|
||||
- **字体细节优化**
|
||||
- 充电行数字与拉丁字母改用 Flyme 字体,中文字符保持 HarmonyOS Sans SC
|
||||
- 解决混合文本下的字体割裂感
|
||||
- 充电详情页所有功率数值同步应用 Flyme 字体
|
||||
|
||||
### 🐛 问题修复
|
||||
|
||||
- 修复主界面充电行在充电器接入初期显示"读取中..."后数值迟迟不刷新的问题
|
||||
- 修复详情页功率数值字体与其它行不统一的问题
|
||||
- 修复 `wired_level` 解析后标定档位显示取整误差(如 `≈8W/L-1` 修正为 `≈7.5W/L-1`)
|
||||
|
||||
### 📝 技术说明
|
||||
|
||||
- `BATTERY_PROPERTY_CURRENT_NOW` 读数为**电池端净电流**(充电器输入减去系统功耗),而非充电器输出端数据
|
||||
- 电池接近满电时数值会明显偏低(涓流阶段),属正常现象
|
||||
- 与系统状态栏显示的充电功率为不同概念,前者反映电池实际吸收,后者反映充电器输出
|
||||
|
||||
---
|
||||
|
||||
## [1.8.0] - 2026-10-11
|
||||
|
||||
### 新增
|
||||
- **夜间模式**:支持浅色 / 深色 / 跟随系统三种模式,可在右上角菜单切换
|
||||
- **主题系统重构**:统一颜色抽象,所有界面颜色由主题管理
|
||||
|
||||
### 优化
|
||||
- 深色主题下潘通色系重新调色,保证对比度
|
||||
- AppBar 与内容区背景统一,消除浅色模式下的分界线
|
||||
|
||||
----
|
||||
|
||||
## [1.7.1] - 2026-09-16
|
||||
|
||||
### 新增
|
||||
- **平均温度显示**:温度面板新增平均温度,与最高/最低温度同排展示(`↑ xx.x℃ ↓ xx.x℃ ⌀ xx.x℃`),更直观了解电池工作温度区间
|
||||
|
||||
### 优化
|
||||
- **数据库升级至 v2**:新增 `temp_avg` 字段,历史数据自动迁移,每日平均温度随扫描自动入库
|
||||
- **构建工具链同步**:适配最新 Flutter SDK 的 Android 构建要求(AGP 9.0 / Kotlin 2.2 / Gradle 9.3)
|
||||
- **Release 打包加固**:补齐 ProGuard 混淆规则,release 版本构建更稳定
|
||||
|
||||
### 修复
|
||||
- 修复 Release 版本因缺少混淆规则文件导致打包失败的问题
|
||||
|
||||
----
|
||||
|
||||
## [1.7.0] - 2026-07-31
|
||||
|
||||
### ✨ 新增功能
|
||||
|
||||
+65
-45
@@ -1,11 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'pages/battery_health_page.dart';
|
||||
import 'services/saf_storage_service.dart';
|
||||
import 'theme/app_colors.dart';
|
||||
import 'theme/theme_service.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await SafStorageService().init();
|
||||
await ThemeService.init(); // 🆕
|
||||
|
||||
runApp(const MyApp());
|
||||
}
|
||||
@@ -15,53 +18,70 @@ class MyApp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: '电池健康度',
|
||||
theme: ThemeData(
|
||||
// 🟢 中文用 HarmonyOS Sans SC
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
// 🟢 数字回退到 FlymeFont
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
// 🟢 统一文字颜色为黑色
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
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,
|
||||
),
|
||||
return ValueListenableBuilder<ThemeMode>(
|
||||
valueListenable: ThemeService.notifier,
|
||||
builder: (context, mode, _) {
|
||||
return MaterialApp(
|
||||
title: '电池健康度',
|
||||
themeMode: mode,
|
||||
theme: _buildTheme(Brightness.light, kLightColors),
|
||||
darkTheme: _buildTheme(Brightness.dark, kDarkColors),
|
||||
home: const BatteryHealthPage(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ThemeData _buildTheme(Brightness brightness, AppColors colors) {
|
||||
return ThemeData(
|
||||
useMaterial3: true,
|
||||
brightness: brightness,
|
||||
scaffoldBackgroundColor: colors.background,
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: colors.background,
|
||||
brightness: brightness,
|
||||
),
|
||||
extensions: [colors], // 🆕 注册 ThemeExtension
|
||||
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: colors.background, // ← 关键:和 Scaffold 一致
|
||||
foregroundColor: colors.textPrimary,
|
||||
// ← 关掉 M3 的滑动变色
|
||||
elevation: 0,
|
||||
|
||||
iconTheme: IconThemeData(color: colors.textPrimary),
|
||||
),
|
||||
|
||||
textTheme: TextTheme(
|
||||
displayMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
useMaterial3: true,
|
||||
headlineMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
bodyMedium: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
bodySmall: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textSecondary,
|
||||
),
|
||||
displayLarge: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontFamilyFallback: const ['Flyme'],
|
||||
color: colors.textPrimary,
|
||||
),
|
||||
),
|
||||
home: const BatteryHealthPage(),
|
||||
debugShowCheckedModeBanner: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-37
@@ -1,16 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
class AboutPage extends StatelessWidget {
|
||||
const AboutPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
final c = context.colors;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'关于',
|
||||
@@ -19,10 +19,8 @@ class AboutPage extends StatelessWidget {
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.transparent,
|
||||
backgroundColor: c.background,
|
||||
elevation: 0,
|
||||
foregroundColor: Theme.of(context).iconTheme.color,
|
||||
iconTheme: IconThemeData(color: Theme.of(context).iconTheme.color),
|
||||
),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
@@ -30,15 +28,12 @@ class AboutPage extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// Logo
|
||||
Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: isDark
|
||||
? Colors.grey.shade800
|
||||
: const Color(0xFFF0F4F8),
|
||||
color: c.surface,
|
||||
),
|
||||
child: ClipOval(
|
||||
child: Image.asset(
|
||||
@@ -50,38 +45,39 @@ class AboutPage extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
Text(
|
||||
'MEIZU Battery Healthy',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'版本 1.7.0',
|
||||
'版本 1.8.0',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 14,
|
||||
color: Colors.grey.shade500,
|
||||
color: c.textTertiary,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Divider(
|
||||
color: Colors.grey.shade300,
|
||||
color: c.divider,
|
||||
thickness: 0.5,
|
||||
indent: 40,
|
||||
endIndent: 40,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
Text(
|
||||
'专机专配 · 仅针对魅族独家开发',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
color: c.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -90,13 +86,12 @@ class AboutPage extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 13,
|
||||
color: Colors.grey.shade400,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// 源码链接按钮
|
||||
InkWell(
|
||||
onTap: () => _launchUrl(context), // 注意这里传入了 context
|
||||
onTap: () => _launchUrl(context),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
@@ -104,34 +99,24 @@ class AboutPage extends StatelessWidget {
|
||||
vertical: 12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isDark
|
||||
? Colors.grey.shade800
|
||||
: const Color(0xFFF0F4F8),
|
||||
color: c.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.code,
|
||||
size: 18,
|
||||
color: Theme.of(context).iconTheme.color,
|
||||
),
|
||||
Icon(Icons.code, size: 18, color: c.textPrimary),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'查看源码 / 反馈',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 14,
|
||||
color: Theme.of(context).iconTheme.color,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
Icons.open_in_new,
|
||||
size: 14,
|
||||
color: Colors.grey.shade500,
|
||||
),
|
||||
Icon(Icons.open_in_new, size: 14, color: c.textTertiary),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -142,7 +127,7 @@ class AboutPage extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade400,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -155,14 +140,11 @@ class AboutPage extends StatelessWidget {
|
||||
Future<void> _launchUrl(BuildContext context) async {
|
||||
const url = 'https://git.whitetop.xyz/lxh2875931338/MEIZU-Battery-Healthy';
|
||||
final uri = Uri.parse(url);
|
||||
|
||||
try {
|
||||
// ✅ 直接尝试打开,不再检查 canLaunchUrl
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
} catch (e) {
|
||||
// 如果打开失败,复制链接并提示
|
||||
debugPrint('打开链接失败: $e');
|
||||
await Clipboard.setData(ClipboardData(text: url));
|
||||
await Clipboard.setData(const ClipboardData(text: url));
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
|
||||
@@ -3,6 +3,9 @@ import 'dart:developer' as dev;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import '../theme/theme_service.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
import '../services/battery_manager_service.dart';
|
||||
|
||||
// --- 本地导入 ---
|
||||
import '../models/device_matching.dart';
|
||||
@@ -62,6 +65,9 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
int? _wiredLevel;
|
||||
bool _isWireless = false;
|
||||
DateTime? _chargingStartTime;
|
||||
double _bmPower = 0.0;
|
||||
double _bmVolt = 0.0;
|
||||
double _bmCurr = 0.0;
|
||||
|
||||
// ---------- SAF 状态 ----------
|
||||
final SafStorageService _safService = SafStorageService();
|
||||
@@ -78,6 +84,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
|
||||
// 轮询定时器(15秒)
|
||||
Timer? _pollTimer;
|
||||
Timer? _bmTimer;
|
||||
|
||||
// ---------- 生命周期 ----------
|
||||
@override
|
||||
@@ -122,7 +129,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
readBatteryCapacity();
|
||||
}
|
||||
});
|
||||
|
||||
_startBmPolling(); // ← 调用,不是定义
|
||||
dev.log('🔵 ========== initState 结束 ==========', name: 'BatteryHealth');
|
||||
}
|
||||
|
||||
@@ -130,6 +137,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
void dispose() {
|
||||
_chargeEventSubscription?.cancel();
|
||||
_pollTimer?.cancel();
|
||||
_bmTimer?.cancel();
|
||||
_dbService.database.then((db) => db.close()).ignore();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -250,6 +258,9 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
_chargeCurr = 0.0;
|
||||
_wiredLevel = null;
|
||||
_chargingStartTime = null;
|
||||
_bmPower = 0.0; // 🆕
|
||||
_bmVolt = 0.0; // 🆕
|
||||
_bmCurr = 0.0; // 🆕
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -608,24 +619,90 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- BM 轮询(1秒) ----------
|
||||
void _startBmPolling() {
|
||||
_bmTimer?.cancel();
|
||||
_bmTimer = Timer.periodic(const Duration(seconds: 1), (_) async {
|
||||
if (!_isCharging) return;
|
||||
try {
|
||||
final d = await BatteryManagerService.fetch();
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_bmPower = d.powerW;
|
||||
_bmVolt = d.voltageV;
|
||||
_bmCurr = d.currentA;
|
||||
});
|
||||
} catch (e) {
|
||||
// 静默降级,保留上一次的值
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- 显示辅助 ----------
|
||||
String _getDisplayPower() {
|
||||
if (!_isCharging) return '';
|
||||
if (_isWireless) {
|
||||
return ChargeUtils.getDisplayPowerWireless(_chargePower);
|
||||
} else {
|
||||
return ChargeUtils.getMainDisplayPowerWired(
|
||||
_chargePower,
|
||||
_wiredLevel,
|
||||
_chargeType,
|
||||
);
|
||||
}
|
||||
return ChargeUtils.getMainDisplayPowerBm(
|
||||
_bmPower,
|
||||
_wiredLevel,
|
||||
_chargeType,
|
||||
_isWireless,
|
||||
);
|
||||
}
|
||||
|
||||
String _getChargeTypeLabel() {
|
||||
return ChargeUtils.getChargeTypeLabel(_isWireless, _chargeType);
|
||||
}
|
||||
|
||||
// 🆕 夜间模式切换弹窗 ← 加在这里
|
||||
void _showThemePicker() {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
final current = ThemeService.notifier.value;
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.brightness_auto),
|
||||
title: const Text('跟随系统'),
|
||||
trailing: current == ThemeMode.system
|
||||
? const Icon(Icons.check)
|
||||
: null,
|
||||
onTap: () {
|
||||
ThemeService.setMode(ThemeMode.system);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.light_mode),
|
||||
title: const Text('浅色'),
|
||||
trailing: current == ThemeMode.light
|
||||
? const Icon(Icons.check)
|
||||
: null,
|
||||
onTap: () {
|
||||
ThemeService.setMode(ThemeMode.light);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.dark_mode),
|
||||
title: const Text('深色'),
|
||||
trailing: current == ThemeMode.dark
|
||||
? const Icon(Icons.check)
|
||||
: null,
|
||||
onTap: () {
|
||||
ThemeService.setMode(ThemeMode.dark);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// ---------- Build ----------
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -645,25 +722,23 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
);
|
||||
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Color.fromRGBO(157, 212, 237, 0.1),
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: context.colors.statusBarTint,
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
// backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
// backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
scrolledUnderElevation: 0,
|
||||
shadowColor: Colors.transparent,
|
||||
surfaceTintColor: Colors.transparent,
|
||||
title: const Text(
|
||||
|
||||
title: Text(
|
||||
'电池健康度',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black,
|
||||
color: context.colors.textPrimary,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
@@ -671,11 +746,11 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: readBatteryCapacity,
|
||||
tooltip: '刷新数据',
|
||||
color: Colors.black,
|
||||
color: context.colors.icon,
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
color: Colors.white,
|
||||
color: context.colors.surface,
|
||||
onSelected: (value) {
|
||||
switch (value) {
|
||||
case 'changelog':
|
||||
@@ -695,7 +770,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
);
|
||||
break;
|
||||
case 'dark_mode':
|
||||
// 夜间模式切换逻辑(1.7.0 再实现)
|
||||
_showThemePicker();
|
||||
break;
|
||||
}
|
||||
},
|
||||
@@ -705,11 +780,7 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
value: 'about', // 🟢 新增
|
||||
child: Text('关于'),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'dark_mode',
|
||||
enabled: false, // 暂时灰显
|
||||
child: Text('夜间模式(开发中)'),
|
||||
),
|
||||
const PopupMenuItem(value: 'dark_mode', child: Text('夜间模式')),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -725,9 +796,9 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
children: [
|
||||
Text(
|
||||
_deviceModel,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
color: context.colors.textTertiary,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
@@ -774,6 +845,9 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
volt: _chargeVolt,
|
||||
curr: _chargeCurr,
|
||||
wiredLevel: _wiredLevel,
|
||||
bmPower: _bmPower, // 🆕
|
||||
bmVolt: _bmVolt, // 🆕
|
||||
bmCurr: _bmCurr, // 🆕
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -804,19 +878,29 @@ class _BatteryHealthPageState extends State<BatteryHealthPage> {
|
||||
),
|
||||
],
|
||||
)
|
||||
: const Center(
|
||||
: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.battery_unknown, size: 64, color: Colors.grey),
|
||||
SizedBox(height: 16),
|
||||
Icon(
|
||||
Icons.battery_unknown,
|
||||
size: 64,
|
||||
color: context.colors.textTertiary,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'暂无数据',
|
||||
style: TextStyle(fontSize: 18, color: Colors.grey),
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
color: context.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'点击右上角刷新尝试',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: context.colors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart'; // 🟢 添加这一行
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
class ChangelogPage extends StatefulWidget {
|
||||
const ChangelogPage({super.key});
|
||||
@@ -15,33 +16,27 @@ class _ChangelogPageState extends State<ChangelogPage>
|
||||
String _markdownContent = '';
|
||||
bool _isLoading = true;
|
||||
String? _error;
|
||||
Widget? _cachedMarkdown;
|
||||
|
||||
// ---------- 滚动 ----------
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
double _scrollProgress = 0.0;
|
||||
bool _isScrolling = false;
|
||||
|
||||
// ---------- 呼吸动画(维持高刷感知) ----------
|
||||
// ---------- 呼吸动画 ----------
|
||||
late AnimationController _breathController;
|
||||
late Animation<double> _breathAnimation;
|
||||
|
||||
// ---------- 原生刷新率控制 ----------
|
||||
// 🟢 改用 static final(不是 const)
|
||||
static final _frameRateChannel = MethodChannel(
|
||||
'com.lxh.battery_health/frame_rate',
|
||||
);
|
||||
|
||||
// ---------- 生命周期 ----------
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadChangelog();
|
||||
|
||||
// 进入页面时申请高刷(原生层)
|
||||
_frameRateChannel.invokeMethod('setHighRefreshRate');
|
||||
|
||||
// 呼吸动画:让进度条在滚动时轻微抖动,维持高刷感知
|
||||
_breathController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
@@ -70,16 +65,13 @@ class _ChangelogPageState extends State<ChangelogPage>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// 离开页面时恢复默认刷新率
|
||||
_frameRateChannel.invokeMethod('clearRefreshRate');
|
||||
|
||||
_scrollController.removeListener(_updateProgress);
|
||||
_scrollController.dispose();
|
||||
_breathController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// ---------- 方法 ----------
|
||||
void _updateProgress() {
|
||||
if (!_scrollController.hasClients) return;
|
||||
final maxScroll = _scrollController.position.maxScrollExtent;
|
||||
@@ -96,7 +88,6 @@ class _ChangelogPageState extends State<ChangelogPage>
|
||||
setState(() {
|
||||
_markdownContent = content;
|
||||
_isLoading = false;
|
||||
_cachedMarkdown = _buildMarkdown(content);
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
@@ -106,78 +97,74 @@ class _ChangelogPageState extends State<ChangelogPage>
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildMarkdown(String content) {
|
||||
Widget _buildMarkdown(BuildContext context, String content) {
|
||||
final c = context.colors;
|
||||
return Markdown(
|
||||
data: content,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
styleSheet: MarkdownStyleSheet(
|
||||
h1: const TextStyle(
|
||||
h1: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
h2: const TextStyle(
|
||||
h2: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black87,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
h3: const TextStyle(
|
||||
h3: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black87,
|
||||
color: c.textSecondary,
|
||||
),
|
||||
p: const TextStyle(
|
||||
p: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
color: Colors.black87,
|
||||
color: c.textSecondary,
|
||||
),
|
||||
listBullet: const TextStyle(
|
||||
listBullet: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
color: Colors.black87,
|
||||
color: c.textSecondary,
|
||||
),
|
||||
code: const TextStyle(
|
||||
code: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 14,
|
||||
color: Colors.black87,
|
||||
backgroundColor: Color(0xFFF5F5F5),
|
||||
color: c.textSecondary,
|
||||
backgroundColor: c.surface,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ---------- Build ----------
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = context.colors;
|
||||
final breathOffset = _isScrolling ? _breathAnimation.value : 0.0;
|
||||
final displayProgress = (_scrollProgress + breathOffset).clamp(0.0, 1.0);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
title: Text(
|
||||
'更新日志',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.black,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
foregroundColor: Colors.black,
|
||||
iconTheme: const IconThemeData(color: Colors.black),
|
||||
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(2.0),
|
||||
child: LinearProgressIndicator(
|
||||
value: displayProgress,
|
||||
backgroundColor: Colors.grey.shade200,
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||
Color.fromRGBO(157, 212, 237, 1.0),
|
||||
),
|
||||
backgroundColor: c.divider,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(c.progressBar),
|
||||
minHeight: 2.0,
|
||||
),
|
||||
),
|
||||
@@ -188,16 +175,16 @@ class _ChangelogPageState extends State<ChangelogPage>
|
||||
? Center(
|
||||
child: Text(
|
||||
_error!,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: _cachedMarkdown ?? const SizedBox.shrink(),
|
||||
child: _buildMarkdown(context, _markdownContent),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// BatteryManager 实时数据(电池端:电压 / 电流 / 功率)
|
||||
class BatteryManagerData {
|
||||
final int voltageMv;
|
||||
final int currentUa;
|
||||
final double powerW;
|
||||
final double temperatureC;
|
||||
final int plugged; // 0=未插, 1=AC, 2=USB, 4=WIRELESS
|
||||
final bool isCharging;
|
||||
|
||||
const BatteryManagerData({
|
||||
required this.voltageMv,
|
||||
required this.currentUa,
|
||||
required this.powerW,
|
||||
required this.temperatureC,
|
||||
required this.plugged,
|
||||
required this.isCharging,
|
||||
});
|
||||
|
||||
factory BatteryManagerData.empty() => const BatteryManagerData(
|
||||
voltageMv: 0,
|
||||
currentUa: 0,
|
||||
powerW: 0,
|
||||
temperatureC: 0,
|
||||
plugged: 0,
|
||||
isCharging: false,
|
||||
);
|
||||
|
||||
factory BatteryManagerData.fromMap(dynamic raw) {
|
||||
if (raw is! Map) return BatteryManagerData.empty();
|
||||
return BatteryManagerData(
|
||||
voltageMv: (raw['voltageMv'] as num?)?.toInt() ?? 0,
|
||||
currentUa: (raw['currentUa'] as num?)?.toInt() ?? 0,
|
||||
powerW: (raw['powerW'] as num?)?.toDouble() ?? 0.0,
|
||||
temperatureC: (raw['temperatureC'] as num?)?.toDouble() ?? 0.0,
|
||||
plugged: (raw['plugged'] as num?)?.toInt() ?? 0,
|
||||
isCharging: raw['isCharging'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
/// 电压 V
|
||||
double get voltageV => voltageMv / 1000.0;
|
||||
|
||||
/// 电流 A
|
||||
double get currentA => currentUa / 1_000_000.0;
|
||||
}
|
||||
|
||||
class BatteryManagerService {
|
||||
static const _channel = MethodChannel('com.lxh.battery_health/charge');
|
||||
|
||||
/// 主动拉取一次
|
||||
static Future<BatteryManagerData> fetch() async {
|
||||
final result = await _channel.invokeMethod('getBatteryManagerData');
|
||||
return BatteryManagerData.fromMap(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@immutable
|
||||
class AppColors extends ThemeExtension<AppColors> {
|
||||
final Color background; // 页面背景
|
||||
final Color surface; // 卡片/面板背景
|
||||
final Color textPrimary; // 主文字
|
||||
final Color textSecondary; // 次要文字
|
||||
final Color textTertiary; // 弱化文字
|
||||
final Color divider; // 分割线
|
||||
final Color icon; // 图标色
|
||||
|
||||
final Color healthGreen; // 健康度 ≥80%
|
||||
final Color healthYellow; // 70~80%
|
||||
final Color healthOrange;
|
||||
final Color healthRed; // <70% 或异常
|
||||
final Color barEmpty; // 无数据柱
|
||||
|
||||
final Color voltUp; // 电压↑
|
||||
final Color voltDown; // 电压↓
|
||||
final Color tempUp;
|
||||
final Color tempDown;
|
||||
|
||||
final Color progressBar; // 更新日志进度条
|
||||
final Color statusBarTint; // 状态栏背景
|
||||
|
||||
const AppColors({
|
||||
required this.background,
|
||||
required this.surface,
|
||||
required this.textPrimary,
|
||||
required this.textSecondary,
|
||||
required this.textTertiary,
|
||||
required this.divider,
|
||||
required this.icon,
|
||||
required this.healthGreen,
|
||||
required this.healthYellow,
|
||||
required this.healthOrange,
|
||||
required this.healthRed,
|
||||
required this.barEmpty,
|
||||
required this.voltUp,
|
||||
required this.voltDown,
|
||||
required this.tempUp,
|
||||
required this.tempDown,
|
||||
required this.progressBar,
|
||||
required this.statusBarTint,
|
||||
});
|
||||
|
||||
@override
|
||||
AppColors copyWith({
|
||||
Color? background,
|
||||
Color? surface,
|
||||
Color? textPrimary,
|
||||
Color? textSecondary,
|
||||
Color? textTertiary,
|
||||
Color? divider,
|
||||
Color? icon,
|
||||
Color? healthGreen,
|
||||
Color? healthYellow,
|
||||
Color? healthOrange,
|
||||
Color? healthRed,
|
||||
Color? barEmpty,
|
||||
Color? voltUp,
|
||||
Color? voltDown,
|
||||
Color? tempUp,
|
||||
Color? tempDown,
|
||||
Color? progressBar,
|
||||
Color? statusBarTint,
|
||||
}) {
|
||||
return AppColors(
|
||||
background: background ?? this.background,
|
||||
surface: surface ?? this.surface,
|
||||
textPrimary: textPrimary ?? this.textPrimary,
|
||||
textSecondary: textSecondary ?? this.textSecondary,
|
||||
textTertiary: textTertiary ?? this.textTertiary,
|
||||
divider: divider ?? this.divider,
|
||||
icon: icon ?? this.icon,
|
||||
healthGreen: healthGreen ?? this.healthGreen,
|
||||
healthYellow: healthYellow ?? this.healthYellow,
|
||||
healthOrange: healthOrange ?? this.healthOrange,
|
||||
healthRed: healthRed ?? this.healthRed,
|
||||
barEmpty: barEmpty ?? this.barEmpty,
|
||||
voltUp: voltUp ?? this.voltUp,
|
||||
voltDown: voltDown ?? this.voltDown,
|
||||
tempUp: tempUp ?? this.tempUp,
|
||||
tempDown: tempDown ?? this.tempDown,
|
||||
progressBar: progressBar ?? this.progressBar,
|
||||
statusBarTint: statusBarTint ?? this.statusBarTint,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
AppColors lerp(ThemeExtension<AppColors>? other, double t) {
|
||||
if (other is! AppColors) return this;
|
||||
return AppColors(
|
||||
background: Color.lerp(background, other.background, t)!,
|
||||
surface: Color.lerp(surface, other.surface, t)!,
|
||||
textPrimary: Color.lerp(textPrimary, other.textPrimary, t)!,
|
||||
textSecondary: Color.lerp(textSecondary, other.textSecondary, t)!,
|
||||
textTertiary: Color.lerp(textTertiary, other.textTertiary, t)!,
|
||||
divider: Color.lerp(divider, other.divider, t)!,
|
||||
icon: Color.lerp(icon, other.icon, t)!,
|
||||
healthGreen: Color.lerp(healthGreen, other.healthGreen, t)!,
|
||||
healthYellow: Color.lerp(healthYellow, other.healthYellow, t)!,
|
||||
healthOrange: Color.lerp(healthOrange, other.healthOrange, t)!,
|
||||
healthRed: Color.lerp(healthRed, other.healthRed, t)!,
|
||||
barEmpty: Color.lerp(barEmpty, other.barEmpty, t)!,
|
||||
voltUp: Color.lerp(voltUp, other.voltUp, t)!,
|
||||
voltDown: Color.lerp(voltDown, other.voltDown, t)!,
|
||||
tempUp: Color.lerp(tempUp, other.tempUp, t)!,
|
||||
tempDown: Color.lerp(tempDown, other.tempDown, t)!,
|
||||
progressBar: Color.lerp(progressBar, other.progressBar, t)!,
|
||||
statusBarTint: Color.lerp(statusBarTint, other.statusBarTint, t)!,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 浅色主题(保持现有视觉)
|
||||
const AppColors kLightColors = AppColors(
|
||||
background: Colors.white,
|
||||
surface: Color(0xFFF0F4F8),
|
||||
textPrimary: Colors.black,
|
||||
textSecondary: Color(0xFF5F5F5F),
|
||||
textTertiary: Colors.grey,
|
||||
divider: Color(0xFFE0E0E0),
|
||||
icon: Colors.black,
|
||||
healthGreen: Color(0xFF00B140),
|
||||
healthYellow: Color(0xFFEFDF00),
|
||||
healthOrange: Color(0xFFD75A16),
|
||||
healthRed: Colors.red,
|
||||
barEmpty: Color(0xFFE0E0E0),
|
||||
voltUp: Colors.red,
|
||||
voltDown: Colors.blue,
|
||||
tempUp: Colors.red,
|
||||
tempDown: Colors.blue,
|
||||
progressBar: Color.fromRGBO(157, 212, 237, 1.0),
|
||||
statusBarTint: Color.fromRGBO(157, 212, 237, 0.1),
|
||||
);
|
||||
|
||||
/// 深色主题(色相保留,明度调整)
|
||||
const AppColors kDarkColors = AppColors(
|
||||
background: Color(0xFF121212),
|
||||
surface: Color(0xFF1E1E1E),
|
||||
textPrimary: Color(0xFFE8E8E8),
|
||||
textSecondary: Color(0xFFA0A0A0),
|
||||
textTertiary: Color(0xFF707070),
|
||||
divider: Color(0xFF2A2A2A),
|
||||
icon: Color(0xFFE8E8E8),
|
||||
healthGreen: Color(0xFF00D14D),
|
||||
healthYellow: Color(0xFFD4C520),
|
||||
healthOrange: Color(0xFFFF7838),
|
||||
healthRed: Color(0xFFFF5252),
|
||||
barEmpty: Color(0xFF2A2A2A),
|
||||
voltUp: Color(0xFFFF5252),
|
||||
voltDown: Color(0xFF5AA9FF),
|
||||
tempUp: Color(0xFFFF5252),
|
||||
tempDown: Color(0xFF5AA9FF),
|
||||
progressBar: Color(0xFF5A9BBD),
|
||||
statusBarTint: Color(0xFF121212),
|
||||
);
|
||||
|
||||
/// 便捷扩展:context.colors.textPrimary
|
||||
extension AppColorsX on BuildContext {
|
||||
AppColors get colors => Theme.of(this).extension<AppColors>()!;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ThemeService {
|
||||
static const _prefKey = 'theme_mode';
|
||||
static final ValueNotifier<ThemeMode> notifier = ValueNotifier(
|
||||
ThemeMode.system,
|
||||
);
|
||||
|
||||
/// 启动时调用(main.dart)
|
||||
static Future<void> init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final saved = prefs.getString(_prefKey);
|
||||
notifier.value = _parse(saved);
|
||||
}
|
||||
|
||||
/// 菜单里调用
|
||||
static Future<void> setMode(ThemeMode mode) async {
|
||||
notifier.value = mode;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(_prefKey, _name(mode));
|
||||
}
|
||||
|
||||
static ThemeMode _parse(String? s) {
|
||||
switch (s) {
|
||||
case 'light':
|
||||
return ThemeMode.light;
|
||||
case 'dark':
|
||||
return ThemeMode.dark;
|
||||
default:
|
||||
return ThemeMode.system;
|
||||
}
|
||||
}
|
||||
|
||||
static String _name(ThemeMode m) {
|
||||
switch (m) {
|
||||
case ThemeMode.light:
|
||||
return 'light';
|
||||
case ThemeMode.dark:
|
||||
return 'dark';
|
||||
case ThemeMode.system:
|
||||
return 'system';
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
-20
@@ -1,7 +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];
|
||||
@@ -13,7 +13,7 @@ class ChargeUtils {
|
||||
return '≈${matchedLevel}W';
|
||||
}
|
||||
|
||||
// ============ 原有有线逻辑(保留兼容,但主界面不再直接调用) ============
|
||||
// ============ 旧的有线逻辑(保留兼容) ============
|
||||
static String getDisplayPowerWired(
|
||||
double power,
|
||||
int? wiredLevel,
|
||||
@@ -34,57 +34,81 @@ 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 (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/${requested}W";
|
||||
}
|
||||
|
||||
// 无档位信息,仅显示实际功率
|
||||
return "≈${actual}w";
|
||||
return "≈${actual}W";
|
||||
}
|
||||
|
||||
// ============ 🟢 1.5.0 新增:二级页面标定档位显示 ============
|
||||
/// 示例:≈80w/L-10
|
||||
// ============ 主界面:BM 电池端功率 + 标定档位 ============
|
||||
/// 示例:5.98W / 7.5W、12.3W、读取中...
|
||||
static String getMainDisplayPowerBm(
|
||||
double bmPower,
|
||||
int? wiredLevel,
|
||||
String chargeType,
|
||||
bool isWireless,
|
||||
) {
|
||||
if (bmPower <= 0 || bmPower > 100) return '读取中...';
|
||||
|
||||
final powerStr = '${bmPower.toStringAsFixed(1)}W';
|
||||
|
||||
if (isWireless || chargeType == 'SDP') return powerStr;
|
||||
|
||||
if (wiredLevel != null && ChargeMaps.wiredPower.containsKey(wiredLevel)) {
|
||||
final requested = ChargeMaps.wiredPower[wiredLevel]!;
|
||||
final requestedStr = requested == requested.roundToDouble()
|
||||
? requested.toInt().toString()
|
||||
: requested.toStringAsFixed(1);
|
||||
return '$powerStr / ${requestedStr}W';
|
||||
}
|
||||
|
||||
return powerStr;
|
||||
}
|
||||
|
||||
// ============ 详情页:标定档位 ============
|
||||
/// 示例:≈80W/L-10、≈7.5W/L-1
|
||||
static String getDetailRequestedPowerWired(
|
||||
double power,
|
||||
int? wiredLevel,
|
||||
String chargeType,
|
||||
) {
|
||||
if (chargeType == "SDP") return "≈7.5w";
|
||||
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";
|
||||
final requested = ChargeMaps.wiredPower[wiredLevel]!;
|
||||
final str = requested == requested.roundToDouble()
|
||||
? requested.toInt().toString()
|
||||
: requested.toStringAsFixed(1);
|
||||
return "≈${str}W/L-$wiredLevel";
|
||||
}
|
||||
|
||||
return "≈${power.round()}w";
|
||||
return "≈${power.round()}W";
|
||||
}
|
||||
|
||||
// ============ 🟢 1.5.0 新增:二级页面实际功率显示 ============
|
||||
// ============ 详情页:实际功率 ============
|
||||
static String getDetailActualPowerWired(double power, String chargeType) {
|
||||
if (chargeType == "SDP") return "≈7.5w";
|
||||
if (chargeType == "SDP") return "≈7.5W";
|
||||
if (power == 0) return "读取中...";
|
||||
return "≈${power.round()}w";
|
||||
return "≈${power.round()}W";
|
||||
}
|
||||
|
||||
// ============ 充电类型标签(保持不变) ============
|
||||
// ============ 充电类型标签 ============
|
||||
static String getChargeTypeLabel(bool isWireless, String chargeType) {
|
||||
if (isWireless) {
|
||||
return chargeType == "无线" ? "无线" : chargeType;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import '../models/data_abnormal_type.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
class BatteryInfoPanel extends StatelessWidget {
|
||||
final double batteryVolt;
|
||||
@@ -9,9 +10,8 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
final double minVolt;
|
||||
final double maxTemp;
|
||||
final double minTemp;
|
||||
final DataAbnormalType abnormalType;
|
||||
|
||||
final double tempAvg;
|
||||
final DataAbnormalType abnormalType;
|
||||
|
||||
const BatteryInfoPanel({
|
||||
super.key,
|
||||
@@ -27,19 +27,22 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = context.colors;
|
||||
final bool isVoltageAbnormal =
|
||||
abnormalType == DataAbnormalType.voltageAbnormal;
|
||||
final Color voltColor = isVoltageAbnormal ? Colors.red : Colors.black;
|
||||
final Color voltColor = isVoltageAbnormal ? c.healthRed : c.textPrimary;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ---------- 电压列 ----------
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoItem(
|
||||
_buildIcon('voltage'),
|
||||
context,
|
||||
_buildIcon(context, 'voltage'),
|
||||
'电压',
|
||||
'${batteryVolt.toStringAsFixed(3)}V',
|
||||
textColor: voltColor,
|
||||
@@ -53,22 +56,17 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.red,
|
||||
color: c.voltUp,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
TextSpan(
|
||||
text: '↑ ',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: '${maxVolt.toStringAsFixed(3)}V',
|
||||
style: TextStyle(
|
||||
color: isVoltageAbnormal ? Colors.red : Colors.red,
|
||||
color: c.voltUp,
|
||||
),
|
||||
),
|
||||
TextSpan(text: '${maxVolt.toStringAsFixed(3)}V'),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -79,22 +77,17 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.blue,
|
||||
color: c.voltDown,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
TextSpan(
|
||||
text: '↓ ',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.blue,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: '${minVolt.toStringAsFixed(3)}V',
|
||||
style: TextStyle(
|
||||
color: isVoltageAbnormal ? Colors.red : Colors.blue,
|
||||
color: c.voltDown,
|
||||
),
|
||||
),
|
||||
TextSpan(text: '${minVolt.toStringAsFixed(3)}V'),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -103,33 +96,34 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
// ---------- 温度列 ----------
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildInfoItem(
|
||||
_buildIcon('temperature'),
|
||||
context,
|
||||
_buildIcon(context, 'temperature'),
|
||||
'温度',
|
||||
'${batteryTemp.toStringAsFixed(0)}℃',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// 🆕 一行显示:↑ max ↓ min [avg] avg
|
||||
Row(
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.red,
|
||||
color: c.tempUp,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
TextSpan(
|
||||
text: '↑ ',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.red,
|
||||
color: c.tempUp,
|
||||
),
|
||||
),
|
||||
TextSpan(text: '${maxTemp.toStringAsFixed(1)}℃'),
|
||||
@@ -139,18 +133,18 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
const SizedBox(width: 6),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.blue,
|
||||
color: c.tempDown,
|
||||
),
|
||||
children: [
|
||||
const TextSpan(
|
||||
TextSpan(
|
||||
text: '↓ ',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.blue,
|
||||
color: c.tempDown,
|
||||
),
|
||||
),
|
||||
TextSpan(text: '${minTemp.toStringAsFixed(1)}℃'),
|
||||
@@ -158,15 +152,15 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
_buildIcon('avg', size: 14),
|
||||
_buildIcon(context, 'avg', size: 14),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
'${tempAvg.toStringAsFixed(1)}℃',
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -178,50 +172,54 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIcon(String type, {double size = 18}) {
|
||||
Widget _buildIcon(BuildContext context, String type, {double size = 18}) {
|
||||
final c = context.colors;
|
||||
final filter = ColorFilter.mode(c.textTertiary, BlendMode.srcIn);
|
||||
switch (type) {
|
||||
case 'voltage':
|
||||
return SvgPicture.asset(
|
||||
'assets/icons/si--lightning-fill.svg',
|
||||
width: size,
|
||||
height: size,
|
||||
colorFilter: const ColorFilter.mode(Colors.grey, BlendMode.srcIn),
|
||||
colorFilter: filter,
|
||||
);
|
||||
case 'temperature':
|
||||
return SvgPicture.asset(
|
||||
'assets/icons/mdi--temperature.svg',
|
||||
width: size,
|
||||
height: size,
|
||||
colorFilter: const ColorFilter.mode(Colors.grey, BlendMode.srcIn),
|
||||
colorFilter: filter,
|
||||
);
|
||||
case 'avg': // 🆕
|
||||
case 'avg':
|
||||
return SvgPicture.asset(
|
||||
'assets/icons/avg.svg',
|
||||
width: size,
|
||||
height: size,
|
||||
colorFilter: const ColorFilter.mode(Colors.grey, BlendMode.srcIn),
|
||||
colorFilter: filter,
|
||||
);
|
||||
default:
|
||||
return Icon(Icons.help_outline, size: size, color: Colors.grey);
|
||||
return Icon(Icons.help_outline, size: size, color: c.textTertiary);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildInfoItem(
|
||||
BuildContext context,
|
||||
Widget icon,
|
||||
String label,
|
||||
String value, {
|
||||
Color textColor = Colors.black,
|
||||
Color? textColor,
|
||||
}) {
|
||||
final c = context.colors;
|
||||
return Row(
|
||||
children: [
|
||||
icon,
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
@@ -231,7 +229,7 @@ class BatteryInfoPanel extends StatelessWidget {
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: textColor,
|
||||
color: textColor ?? c.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/data_abnormal_type.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
class BatterySummary extends StatelessWidget {
|
||||
final double healthPercent;
|
||||
@@ -19,25 +20,23 @@ class BatterySummary extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = context.colors;
|
||||
final bool isAbnormal = abnormalType != DataAbnormalType.none;
|
||||
final bool isCapacityAbnormal =
|
||||
abnormalType == DataAbnormalType.capacityTooLow ||
|
||||
abnormalType == DataAbnormalType.capacityTooHigh;
|
||||
|
||||
// 健康度颜色:异常时红色,否则按阈值
|
||||
final Color healthColor = isAbnormal
|
||||
? Colors.red
|
||||
: (healthPercent < 70 ? Colors.red : Colors.black);
|
||||
? c.healthRed
|
||||
: (healthPercent < 70 ? c.healthRed : c.textPrimary);
|
||||
|
||||
// 容量颜色:异常时红色,否则灰色
|
||||
final Color capacityColor = isCapacityAbnormal
|
||||
? Colors.red
|
||||
: const Color(0xFF5F5F5F);
|
||||
? c.healthRed
|
||||
: c.textSecondary;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
// 健康度大数字
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
@@ -60,34 +59,33 @@ class BatterySummary extends StatelessWidget {
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w300,
|
||||
height: 1.0,
|
||||
color: healthColor == Colors.red
|
||||
? Colors.red
|
||||
: Colors.grey.shade600,
|
||||
color: healthColor == c.healthRed
|
||||
? c.healthRed
|
||||
: c.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
// cycles + mAh
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1.2,
|
||||
color: Colors.black,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: '$cycleCount'),
|
||||
const TextSpan(
|
||||
TextSpan(
|
||||
text: ' cycles',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
color: Colors.black,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../utils/charge_utils.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
class ChargeDetailPage extends StatelessWidget {
|
||||
final String chargeType;
|
||||
@@ -9,6 +10,9 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
final double volt;
|
||||
final double curr;
|
||||
final int? wiredLevel;
|
||||
final double bmPower;
|
||||
final double bmVolt;
|
||||
final double bmCurr;
|
||||
|
||||
const ChargeDetailPage({
|
||||
super.key,
|
||||
@@ -18,6 +22,9 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
required this.volt,
|
||||
required this.curr,
|
||||
this.wiredLevel,
|
||||
this.bmPower = 0,
|
||||
this.bmVolt = 0,
|
||||
this.bmCurr = 0,
|
||||
});
|
||||
|
||||
String _getProtocolDisplay() {
|
||||
@@ -41,61 +48,71 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = context.colors;
|
||||
final isDark = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: const SystemUiOverlayStyle(
|
||||
statusBarColor: Color.fromRGBO(157, 212, 237, 0.1),
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
statusBarBrightness: Brightness.dark,
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: c.statusBarTint,
|
||||
statusBarIconBrightness: isDark ? Brightness.light : Brightness.dark,
|
||||
statusBarBrightness: Theme.of(context).brightness,
|
||||
),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
title: const Text('充电详情'),
|
||||
backgroundColor: Colors.white,
|
||||
backgroundColor: c.background,
|
||||
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()),
|
||||
// ========== BMS 来源 ==========
|
||||
_buildSectionTitle(context, 'BMS 日志'),
|
||||
_buildTextRow(context, '协议', _getProtocolDisplay()),
|
||||
const Divider(),
|
||||
|
||||
if (!isWireless) ...[
|
||||
_buildTextRow('标定档位', _getRequestedDisplay()),
|
||||
_buildTextRow(
|
||||
context,
|
||||
'标定档位',
|
||||
_getRequestedDisplay(),
|
||||
valueFont: 'Flyme',
|
||||
),
|
||||
const Divider(),
|
||||
_buildTextRow('实际功率', _getActualDisplay()),
|
||||
_buildTextRow(
|
||||
context,
|
||||
'实际功率',
|
||||
_getActualDisplay(),
|
||||
valueFont: 'Flyme',
|
||||
),
|
||||
const Divider(),
|
||||
] else ...[
|
||||
_buildTextRow('功率', ChargeUtils.getDisplayPowerWireless(power)),
|
||||
_buildTextRow(
|
||||
context,
|
||||
'功率',
|
||||
ChargeUtils.getDisplayPowerWireless(power),
|
||||
valueFont: 'Flyme',
|
||||
),
|
||||
const Divider(),
|
||||
],
|
||||
|
||||
_buildDetailRow('电压', volt, 'V'),
|
||||
_buildDetailRow(context, '电压', volt, 'V'),
|
||||
const Divider(),
|
||||
_buildDetailRow('电流', curr, 'A'),
|
||||
_buildDetailRow(context, '电流', curr, 'A'),
|
||||
const Divider(),
|
||||
|
||||
if (isWireless) _buildTextRow('类型', '无线'),
|
||||
if (!isWireless && wiredLevel == null) _buildTextRow('档位', '自动'),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ========== BM 来源 ==========
|
||||
_buildSectionTitle(context, 'BatteryManager(电池端)'),
|
||||
_buildDetailRow(context, '电压', bmVolt, 'V'),
|
||||
const Divider(),
|
||||
_buildDetailRow(context, '电流', bmCurr, 'A'),
|
||||
const Divider(),
|
||||
bmPower > 0
|
||||
? _buildDetailRow(context, '功率', bmPower, 'W')
|
||||
: _buildTextRow(context, '功率', '读取中...'),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Text(
|
||||
'数据来自 BMS 实时日志',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 12,
|
||||
color: Colors.grey.shade500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -103,8 +120,29 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 纯文本行(协议、功率、档位等)
|
||||
Widget _buildTextRow(String label, String value) {
|
||||
Widget _buildSectionTitle(BuildContext context, String title) {
|
||||
final c = context.colors;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextRow(
|
||||
BuildContext context,
|
||||
String label,
|
||||
String value, {
|
||||
String valueFont = 'HarmonyOS_Sans_SC',
|
||||
}) {
|
||||
final c = context.colors;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: Row(
|
||||
@@ -112,20 +150,20 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC', // 复杂字符串保持 Harmony
|
||||
style: TextStyle(
|
||||
fontFamily: valueFont,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.black87,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -133,8 +171,13 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// 数值行(电压/电流,数字用 Flyme,单位用 Harmony)
|
||||
Widget _buildDetailRow(String label, double value, String unit) {
|
||||
Widget _buildDetailRow(
|
||||
BuildContext context,
|
||||
String label,
|
||||
double value,
|
||||
String unit,
|
||||
) {
|
||||
final c = context.colors;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
child: Row(
|
||||
@@ -142,24 +185,24 @@ class ChargeDetailPage extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.black87,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: value.toStringAsFixed(2),
|
||||
style: const TextStyle(fontFamily: 'Flyme'), // 🟢 数字用 Flyme
|
||||
style: const TextStyle(fontFamily: 'Flyme'),
|
||||
),
|
||||
TextSpan(
|
||||
text: unit,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
class ChargeEntry extends StatelessWidget {
|
||||
final String summary;
|
||||
@@ -14,18 +15,23 @@ class ChargeEntry extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = context.colors;
|
||||
return GestureDetector(
|
||||
onTap: isCharging ? onTap : null,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
summary,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC', // 🟢 混合文本用 Harmony
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.black87,
|
||||
Flexible(
|
||||
child: RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text: TextSpan(
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
children: _buildSpans(summary),
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
@@ -36,7 +42,7 @@ class ChargeEntry extends StatelessWidget {
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade700,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
@@ -46,7 +52,7 @@ class ChargeEntry extends StatelessWidget {
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.grey.shade700,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -55,4 +61,54 @@ class ChargeEntry extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 按 CJK / 非 CJK 拆分字符串,分别应用 HarmonyOS / Flyme
|
||||
List<TextSpan> _buildSpans(String text) {
|
||||
final spans = <TextSpan>[];
|
||||
if (text.isEmpty) return spans;
|
||||
|
||||
final buffer = StringBuffer();
|
||||
bool? isCJK;
|
||||
|
||||
void flush() {
|
||||
if (buffer.isEmpty) return;
|
||||
spans.add(
|
||||
TextSpan(
|
||||
text: buffer.toString(),
|
||||
style: TextStyle(
|
||||
fontFamily: (isCJK ?? false) ? 'HarmonyOS_Sans_SC' : 'Flyme',
|
||||
),
|
||||
),
|
||||
);
|
||||
buffer.clear();
|
||||
}
|
||||
|
||||
for (final rune in text.runes) {
|
||||
final cjk = _isCJKRune(rune);
|
||||
if (isCJK == null || cjk == isCJK) {
|
||||
buffer.writeCharCode(rune);
|
||||
isCJK = cjk;
|
||||
} else {
|
||||
flush();
|
||||
buffer.writeCharCode(rune);
|
||||
isCJK = cjk;
|
||||
}
|
||||
}
|
||||
flush();
|
||||
return spans;
|
||||
}
|
||||
|
||||
bool _isCJKRune(int rune) {
|
||||
// CJK 统一表意文字
|
||||
if (rune >= 0x4E00 && rune <= 0x9FFF) return true;
|
||||
// CJK 扩展 A
|
||||
if (rune >= 0x3400 && rune <= 0x4DBF) return true;
|
||||
// 中文标点(。、,:;等)
|
||||
if (rune >= 0x3000 && rune <= 0x303F) return true;
|
||||
// CJK 兼容符号
|
||||
if (rune >= 0xFE30 && rune <= 0xFE4F) return true;
|
||||
// 全角字符
|
||||
if (rune >= 0xFF00 && rune <= 0xFFEF) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_colors.dart';
|
||||
|
||||
// --- 潘通色定义 ---
|
||||
const Color kHealthGreen = Color(0xFF00B140);
|
||||
const Color kHealthYellow = Color(0xFFEFDF00);
|
||||
const Color kHealthOrange = Color(0xFFD75A16);
|
||||
|
||||
/// 趋势图柱状图组件
|
||||
class TrendChart extends StatelessWidget {
|
||||
final List<Map<String, dynamic>> data;
|
||||
final int designCap;
|
||||
@@ -14,6 +9,8 @@ class TrendChart extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final c = context.colors;
|
||||
|
||||
List<Map<String, dynamic>> displayData = data.isNotEmpty
|
||||
? data
|
||||
: _getMockData();
|
||||
@@ -48,12 +45,13 @@ class TrendChart extends StatelessWidget {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
Text(
|
||||
'容量百分比变动趋势(近15天)',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: c.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -64,13 +62,13 @@ class TrendChart extends StatelessWidget {
|
||||
height: 180,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: const [
|
||||
children: [
|
||||
Text(
|
||||
'100',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 10,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
height: 1.0,
|
||||
),
|
||||
),
|
||||
@@ -79,7 +77,7 @@ class TrendChart extends StatelessWidget {
|
||||
style: TextStyle(
|
||||
fontFamily: 'Flyme',
|
||||
fontSize: 10,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
height: 1.0,
|
||||
),
|
||||
),
|
||||
@@ -106,14 +104,14 @@ class TrendChart extends StatelessWidget {
|
||||
Color barColor;
|
||||
if (value > 0) {
|
||||
if (value >= 80) {
|
||||
barColor = kHealthGreen;
|
||||
barColor = c.healthGreen;
|
||||
} else if (value >= 70) {
|
||||
barColor = kHealthYellow;
|
||||
barColor = c.healthYellow;
|
||||
} else {
|
||||
barColor = Colors.red;
|
||||
barColor = c.healthRed;
|
||||
}
|
||||
} else {
|
||||
barColor = Colors.grey.shade300;
|
||||
barColor = c.barEmpty;
|
||||
}
|
||||
double clampedValue = value.clamp(70.0, 100.0);
|
||||
double heightFactor =
|
||||
@@ -144,10 +142,10 @@ class TrendChart extends StatelessWidget {
|
||||
bottom: 2,
|
||||
child: Text(
|
||||
sevenDaysAgoDate,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 9,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
height: 1.0,
|
||||
),
|
||||
),
|
||||
@@ -158,10 +156,10 @@ class TrendChart extends StatelessWidget {
|
||||
bottom: 2,
|
||||
child: Text(
|
||||
todayDate,
|
||||
style: const TextStyle(
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 9,
|
||||
color: Colors.black,
|
||||
color: c.textPrimary,
|
||||
height: 1.0,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
@@ -176,14 +174,14 @@ class TrendChart extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
if (percents.every((v) => v == 0))
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 8.0),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
'暂无历史数据,请点击刷新按钮更新',
|
||||
style: TextStyle(
|
||||
fontFamily: 'HarmonyOS_Sans_SC',
|
||||
fontSize: 12,
|
||||
color: Colors.grey,
|
||||
color: c.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
+1
-1
@@ -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.7.2
|
||||
version: 1.9.0
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.2
|
||||
|
||||
Reference in New Issue
Block a user