Skip to content

Fix: Android model persistence and folder recognition - #2

Merged
Kiastr merged 1 commit into
masterfrom
fix/android-bugs
Jul 15, 2026
Merged

Fix: Android model persistence and folder recognition#2
Kiastr merged 1 commit into
masterfrom
fix/android-bugs

Conversation

@Kiastr

@Kiastr Kiastr commented Jul 15, 2026

Copy link
Copy Markdown
Owner

This PR fixes two reported bugs in the Android version:

  1. Model persistence: Added SharedPreferences to save and restore the model path on app restart.
  2. Folder recognition: Added MANAGE_EXTERNAL_STORAGE permission and improved directory listing logic to ensure images in selected folders are correctly identified on newer Android versions.

Copilot AI review requested due to automatic review settings July 15, 2026 08:10
@Kiastr
Kiastr merged commit e876efc into master Jul 15, 2026
1 check passed
@Kiastr
Kiastr deleted the fix/android-bugs branch July 15, 2026 08:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR targets two Android-specific bugs in the Flutter app: persisting the last-used ONNX model path across restarts and improving folder image discovery on newer Android versions where direct filesystem access is more restricted.

Changes:

  • Added shared_preferences dependency and implemented saving/restoring the last model path.
  • Updated permission requests to include “all files access” flow (Android 11+) to improve external directory access.
  • Tweaked batch directory listing to more explicitly filter file entities.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
android/pubspec.yaml Adds shared_preferences for persisting model path.
android/lib/home_page.dart Implements model path persistence, updates permission requests, and adjusts batch folder enumeration.
android/android/app/src/main/AndroidManifest.xml Declares MANAGE_EXTERNAL_STORAGE permission for broader external storage access.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 54 to +58
Future<void> _requestPermissions() async {
// 申请存储权限(传统文件访问)
await Permission.storage.request();
if (await Permission.photos.request().isDenied) {
// 低版本用 storage 已覆盖
// 申请管理所有文件权限 (Android 11+),这能解决 Directory.listSync() 无法访问外部目录的问题
if (await Permission.manageExternalStorage.request().isGranted) {
Comment on lines +63 to +72
Future<void> _loadSavedModel() async {
final prefs = await SharedPreferences.getInstance();
final savedPath = prefs.getString('last_model_path');
if (savedPath != null && File(savedPath).existsSync()) {
setState(() {
_modelPath = savedPath;
_log = '已恢复上次使用的模型';
});
}
}
_modelPath = path;
_log = '已选择本地模型: $path';
});
_saveModelPath(path);
Comment on lines 133 to +137
setState(() {
_modelPath = savePath;
_log = '模型下载完成: $savePath';
});
_saveModelPath(savePath);
Comment on lines 235 to +239
Future<void> _runBatch() async {
final files = Directory(_inputDir!)
.listSync()
.whereType<File>()
.listSync(recursive: false, followLinks: false)
.where((entity) => entity is File)
.cast<File>()
Comment thread android/pubspec.yaml
Comment on lines 18 to +23
dio: ^4.0.6
# 应用私有目录
path_provider: ^2.0.15
# 存储/相册权限
permission_handler: ^9.2.0
shared_preferences: ^2.0.15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants