Skip to content

Commit 2e15543

Browse files
committed
Initial release - Flutter document layout detection plugin
0 parents  commit 2e15543

105 files changed

Lines changed: 7465 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
28+
/pubspec.lock
29+
**/doc/api/
30+
.dart_tool/
31+
.flutter-plugins
32+
.flutter-plugins-dependencies
33+
build/
34+
35+
# Claude
36+
.claude/
37+
CLAUDE.md
38+
39+
# Documentation (internal use only)
40+
doc/
41+
42+
# Large model files (download separately)
43+
ai_model/
44+
*.onnx
45+
46+
# Build scripts (not for distribution)
47+
scripts/
48+
49+
# Python virtual environment
50+
__pycache__/
51+
*.pyc
52+
53+
# Native libraries (download separately)
54+
ios/libflutter_doclayout_kit.a
55+
android/src/main/jniLibs/
56+
android/src/main/cpp/include/

.metadata

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "c23637390482d4cf9598c3ce3f2be31aa7332daf"
8+
channel: "stable"
9+
10+
project_type: plugin_ffi
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
17+
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
18+
- platform: android
19+
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
20+
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
21+
- platform: ios
22+
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
23+
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
24+
25+
# User provided section
26+
27+
# List of Local paths (relative to this file) that should be
28+
# ignored by the migrate tool.
29+
#
30+
# Files that are not part of the templates will be ignored by default.
31+
unmanaged_files:
32+
- 'lib/main.dart'
33+
- 'ios/Runner.xcodeproj/project.pbxproj'

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* TODO: Describe initial release.

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: Add your license here.

PERMISSIONS.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# 權限說明 / Permissions Guide
2+
3+
本專案需要相機和相簿權限來進行文件掃描和圖片選擇。
4+
5+
This project requires camera and photo library permissions for document scanning and image selection.
6+
7+
---
8+
9+
## iOS 權限 / iOS Permissions
10+
11+
已在 `ios/Runner/Info.plist` 中配置:
12+
13+
### NSCameraUsageDescription
14+
**用途:** 使用相機掃描文件
15+
**說明文字:** "此應用程式需要使用相機來掃描和辨識文件佈局"
16+
17+
### NSPhotoLibraryUsageDescription
18+
**用途:** 從相簿選擇圖片
19+
**說明文字:** "此應用程式需要存取相簿以選擇要分析的文件圖片"
20+
21+
### NSPhotoLibraryAddUsageDescription
22+
**用途:** 儲存處理後的圖片到相簿
23+
**說明文字:** "此應用程式需要將處理後的文件圖片儲存到相簿"
24+
25+
---
26+
27+
## Android 權限 / Android Permissions
28+
29+
已在 `android/app/src/main/AndroidManifest.xml` 中配置:
30+
31+
### CAMERA
32+
```xml
33+
<uses-permission android:name="android.permission.CAMERA"/>
34+
```
35+
**用途:** 使用相機掃描文件
36+
37+
### READ_EXTERNAL_STORAGE
38+
```xml
39+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
40+
android:maxSdkVersion="32"/>
41+
```
42+
**用途:** 讀取相簿圖片(Android 12 及以下)
43+
44+
### READ_MEDIA_IMAGES
45+
```xml
46+
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
47+
```
48+
**用途:** 讀取相簿圖片(Android 13+)
49+
50+
### Camera Feature
51+
```xml
52+
<uses-feature android:name="android.hardware.camera" android:required="false"/>
53+
```
54+
**說明:** 聲明使用相機功能,但不是必需(支援無相機裝置)
55+
56+
---
57+
58+
## 使用說明 / Usage Guide
59+
60+
### 自動請求權限
61+
62+
使用 `image_picker` 套件時,權限會自動請求:
63+
64+
```dart
65+
import 'package:image_picker/image_picker.dart';
66+
67+
final ImagePicker picker = ImagePicker();
68+
69+
// 從相機拍照 - 會自動請求相機權限
70+
final XFile? photo = await picker.pickImage(source: ImageSource.camera);
71+
72+
// 從相簿選擇 - 會自動請求相簿權限
73+
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
74+
```
75+
76+
### 手動檢查權限(可選)
77+
78+
如果需要提前檢查權限狀態,可使用 `permission_handler` 套件:
79+
80+
```yaml
81+
dependencies:
82+
permission_handler: ^11.0.0
83+
```
84+
85+
```dart
86+
import 'package:permission_handler/permission_handler.dart';
87+
88+
// 檢查並請求相機權限
89+
Future<void> requestCameraPermission() async {
90+
final status = await Permission.camera.request();
91+
if (status.isGranted) {
92+
// 權限已授予
93+
} else if (status.isDenied) {
94+
// 權限被拒絕
95+
} else if (status.isPermanentlyDenied) {
96+
// 權限被永久拒絕,需要引導用戶到設定頁面
97+
openAppSettings();
98+
}
99+
}
100+
101+
// 檢查並請求相簿權限
102+
Future<void> requestGalleryPermission() async {
103+
final status = await Permission.photos.request();
104+
// 處理結果...
105+
}
106+
```
107+
108+
---
109+
110+
## 權限說明文字自定義 / Customizing Permission Messages
111+
112+
### iOS
113+
114+
編輯 `ios/Runner/Info.plist` 中的說明文字:
115+
116+
```xml
117+
<key>NSCameraUsageDescription</key>
118+
<string>您的自定義說明文字</string>
119+
```
120+
121+
### Android
122+
123+
Android 權限說明由系統自動顯示,無法自定義。但可以在請求權限前顯示自己的說明對話框。
124+
125+
---
126+
127+
## 常見問題 / FAQ
128+
129+
### Q: 為什麼有兩個 Android 相簿權限?
130+
131+
A: Android 13 (API 33) 引入了新的細粒度媒體權限:
132+
- `READ_EXTERNAL_STORAGE` - 適用於 Android 12 及以下
133+
- `READ_MEDIA_IMAGES` - 適用於 Android 13+
134+
135+
兩者都配置可確保所有 Android 版本都能正常工作。
136+
137+
### Q: 如果用戶拒絕權限怎麼辦?
138+
139+
A: 應用會無法使用相機或相簿功能。建議:
140+
1. 在請求權限前顯示說明對話框
141+
2. 如果被拒絕,提供引導到設定頁面的選項
142+
3. 提供替代方案(例如:只允許手動輸入)
143+
144+
### Q: 需要其他權限嗎?
145+
146+
A: 不需要。本專案只需要相機和相簿權限。如果您的應用有其他功能(如網路請求、位置等),請自行添加。
147+
148+
---
149+
150+
## 隱私政策建議 / Privacy Policy Recommendations
151+
152+
如果您的應用要上架到 App Store 或 Google Play,請在隱私政策中說明:
153+
154+
1. **收集的資料:** 相機拍攝的圖片、相簿選擇的圖片
155+
2. **使用目的:** 文件佈局分析和辨識
156+
3. **資料處理:**
157+
- 所有處理在本地裝置進行
158+
- 不會上傳到伺服器
159+
- 不會儲存用戶圖片(除非用戶明確選擇儲存)
160+
4. **第三方共享:**
161+
162+
---
163+
164+
## 更新日誌 / Changelog
165+
166+
### 2024-11-25
167+
- ✅ 添加 iOS 相機和相簿權限宣告
168+
- ✅ Android 權限已配置(之前已存在)
169+
- ✅ 建立權限說明文件

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# flutter_doclayout_kit
2+
3+
A new Flutter project.
4+
5+
## Getting Started
6+
7+
This project is a starting point for a Flutter
8+
[FFI plugin](https://flutter.dev/to/ffi-package),
9+
a specialized package that includes native code directly invoked with Dart FFI.
10+
11+
## Project structure
12+
13+
This template uses the following structure:
14+
15+
* `src`: Contains the native source code, and a CmakeFile.txt file for building
16+
that source code into a dynamic library.
17+
18+
* `lib`: Contains the Dart code that defines the API of the plugin, and which
19+
calls into the native code using `dart:ffi`.
20+
21+
* platform folders (`android`, `ios`, `windows`, etc.): Contains the build files
22+
for building and bundling the native code library with the platform application.
23+
24+
## Building and bundling native code
25+
26+
The `pubspec.yaml` specifies FFI plugins as follows:
27+
28+
```yaml
29+
plugin:
30+
platforms:
31+
some_platform:
32+
ffiPlugin: true
33+
```
34+
35+
This configuration invokes the native build for the various target platforms
36+
and bundles the binaries in Flutter applications using these FFI plugins.
37+
38+
This can be combined with dartPluginClass, such as when FFI is used for the
39+
implementation of one platform in a federated plugin:
40+
41+
```yaml
42+
plugin:
43+
implements: some_other_plugin
44+
platforms:
45+
some_platform:
46+
dartPluginClass: SomeClass
47+
ffiPlugin: true
48+
```
49+
50+
A plugin can have both FFI and method channels:
51+
52+
```yaml
53+
plugin:
54+
platforms:
55+
some_platform:
56+
pluginClass: SomeName
57+
ffiPlugin: true
58+
```
59+
60+
The native build systems that are invoked by FFI (and method channel) plugins are:
61+
62+
* For Android: Gradle, which invokes the Android NDK for native builds.
63+
* See the documentation in android/build.gradle.
64+
* For iOS and MacOS: Xcode, via CocoaPods.
65+
* See the documentation in ios/flutter_doclayout_kit.podspec.
66+
* See the documentation in macos/flutter_doclayout_kit.podspec.
67+
* For Linux and Windows: CMake.
68+
* See the documentation in linux/CMakeLists.txt.
69+
* See the documentation in windows/CMakeLists.txt.
70+
71+
## Binding to native code
72+
73+
To use the native code, bindings in Dart are needed.
74+
To avoid writing these by hand, they are generated from the header file
75+
(`src/flutter_doclayout_kit.h`) by `package:ffigen`.
76+
Regenerate the bindings by running `dart run ffigen --config ffigen.yaml`.
77+
78+
## Invoking native code
79+
80+
Very short-running native functions can be directly invoked from any isolate.
81+
For example, see `sum` in `lib/flutter_doclayout_kit.dart`.
82+
83+
Longer-running functions should be invoked on a helper isolate to avoid
84+
dropping frames in Flutter applications.
85+
For example, see `sumAsync` in `lib/flutter_doclayout_kit.dart`.
86+
87+
## Flutter help
88+
89+
For help getting started with Flutter, view our
90+
[online documentation](https://docs.flutter.dev), which offers tutorials,
91+
samples, guidance on mobile development, and a full API reference.
92+

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options

android/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx

0 commit comments

Comments
 (0)