2 Commits

5 changed files with 86 additions and 40 deletions
+16 -14
View File
@@ -1,20 +1,22 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!--<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />-->
<application
android:label="@string/app_name"
android:name="${applicationName}"
android:icon="@drawable/logo"
android:requestLegacyExternalStorage="true">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<application
android:label="@string/app_name"
android:name="${applicationName}"
android:icon="@drawable/logo"
android:requestLegacyExternalStorage="true"
android:theme="@style/LaunchTheme"> <!-- 全局先用 LaunchTheme -->
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/AppTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
+6 -15
View File
@@ -1,18 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
the Flutter engine draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- 状态栏背景白色 -->
<item name="android:statusBarColor">@android:color/white</item>
<!-- 状态栏图标亮色(深色图标) -->
<item name="android:windowLightStatusBar">true</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
</resources>
+9 -3
View File
@@ -885,11 +885,17 @@ class _BatteryHealthPageState extends State<BatteryHealthPage>
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark,
value: SystemUiOverlayStyle(
statusBarColor: Colors.white,
statusBarIconBrightness: Brightness.dark,
statusBarBrightness: Brightness.dark,
),
child: Scaffold(
backgroundColor: Colors.white, // 🟢 页面背景色与 AppBar 统一
appBar: AppBar(
backgroundColor: const Color.fromARGB(0, 255, 255, 255),
elevation: 0,
backgroundColor: Colors.white,
elevation: 0, // 🟢 去掉阴影
scrolledUnderElevation: 0, // 🟢 滚动时也不出现阴影
title: const Text(
'电池健康度',
style: TextStyle(
+54 -7
View File
@@ -3,6 +3,8 @@ import 'package:flutter/services.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../models/saf_permission_state.dart';
/// SAF 存储服务
/// 负责管理通过 SAF 授权的文件夹访问
class SafStorageService {
static final SafStorageService _instance = SafStorageService._internal();
factory SafStorageService() => _instance;
@@ -14,7 +16,7 @@ class SafStorageService {
static const String _prefKeySafUri = 'saf_storage_uri';
String? _cachedUri;
// 🟢 初始化从 SharedPreferences 恢复 URI
/// 初始化从 SharedPreferences 恢复 URI
Future<void> init() async {
try {
final prefs = await SharedPreferences.getInstance();
@@ -30,14 +32,16 @@ class SafStorageService {
}
}
/// 获取当前授权状态(简化版,直接根据缓存判断)
Future<SafPermissionState> getPermissionState() async {
if (_cachedUri == null || _cachedUri!.isEmpty) {
return SafPermissionState.unauthorized;
}
// 🟢 直接返回 authorized,相信缓存
// 直接返回 authorized,相信缓存
return SafPermissionState.authorized;
}
/// 请求 SAF 授权(引导用户选择文件夹)
Future<SafAuthorizationResult> requestPermission() async {
try {
final String? uriString = await _channel.invokeMethod('selectFolder');
@@ -62,23 +66,57 @@ class SafStorageService {
}
}
/// 🟢 将 URI 传递给 Kotlin 端(用于恢复 safUri
Future<bool> restoreUri() async {
if (_cachedUri == null || _cachedUri!.isEmpty) {
if (kDebugMode) {
print('[SAF] restoreUri: 缓存 URI 为空');
}
return false;
}
try {
final bool? result = await _channel.invokeMethod('restoreUri', {
'uri': _cachedUri,
});
if (result == true) {
if (kDebugMode) {
print('[SAF] restoreUri 成功: $_cachedUri');
}
return true;
} else {
if (kDebugMode) {
print('[SAF] restoreUri 失败: 返回 false');
}
return false;
}
} catch (e) {
if (kDebugMode) {
print('[SAF] restoreUri 异常: $e');
}
return false;
}
}
/// 检查指定日期的日志文件是否存在
Future<bool> logFileExists(String fileName) async {
final state = await getPermissionState();
if (state != SafPermissionState.authorized) return false;
try {
final files = await _channel.invokeMethod('listFiles');
if (files is List) {
return files.contains(fileName);
}
return false;
final files = await listFiles();
return files.contains(fileName);
} catch (e) {
return false;
}
}
/// 读取日志文件内容(返回行列表)
Future<List<String>> readLogFile(String fileName) async {
// 🟢 先尝试恢复 URI
await restoreUri();
final state = await getPermissionState();
if (state != SafPermissionState.authorized) return [];
try {
final String? content = await _channel.invokeMethod('readLogFile', {
'fileName': fileName,
@@ -93,9 +131,14 @@ class SafStorageService {
}
}
/// 获取文件夹中的文件列表
Future<List<String>> listFiles() async {
// 🟢 先尝试恢复 URI
await restoreUri();
final state = await getPermissionState();
if (state != SafPermissionState.authorized) return [];
try {
final result = await _channel.invokeMethod('listFiles');
if (result is List) {
@@ -110,16 +153,19 @@ class SafStorageService {
}
}
/// 验证授权是否有效(简化版)
Future<bool> validatePermission() async {
final state = await getPermissionState();
return state == SafPermissionState.authorized;
}
/// 清除缓存
void _clearCache() {
_cachedUri = null;
_saveUri(null);
}
/// 保存 URI 到 SharedPreferences
Future<void> _saveUri(String? uri) async {
try {
final prefs = await SharedPreferences.getInstance();
@@ -141,5 +187,6 @@ class SafStorageService {
}
}
/// 获取缓存的 URI(用于调试)
String? get cachedUri => _cachedUri;
}
+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.3.0-dev.4
version: 1.4.0
environment:
sdk: ^3.9.2