README.OpenHarmony_CN.md
3.38 KB
模板版本: v0.0.1
flutter_barcode_scanner
本项目基于 flutter_barcode_scanner 开发。
1. 安装与使用
1.1 安装方式
进入到工程目录并在 pubspec.yaml 中添加以下依赖:
pubspec.yaml
...
dependencies:
flutter_barcode_scanner_ohos:
git:
url: https://gitcode.com/openharmony-sig/fluttertpc_flutter_barcode_scanner.git
path: ohos
...
执行命令
flutter pub get
1.2 使用案例
使用案例详见 ohos/example
2. 约束与限制
2.1 兼容性
在以下版本中已测试通过
- Flutter: 3.7.12-ohos-1.0.6; SDK: 5.0.0(12); IDE: DevEco Studio: 5.0.13.200; ROM: 5.1.0.120 SP3;
- Flutter: 3.22.1-ohos-1.0.1; SDK: 5.0.0(12); IDE: DevEco Studio: 5.0.13.200; ROM: 5.1.0.120 SP3;
2.2 权限要求
2.2.1 在 entry 目录下的module.json5中添加权限
打开 entry/src/main/module.json5,添加:
...
"requestPermissions": [
+ {
+ "name": "ohos.permission.CAMERA",
+ "reason": "$string:camera_reason",
+ "usedScene": {
+ "abilities": [
+ "EntryAbility"
+ ],
+ "when":"inuse"
+ }
+ }
]
2.2.2 在 entry 目录下添加申请以上权限的原因
打开 entry/src/main/resources/base/element/string.json,添加:
...
{
"string": [
+ {
+ "name": "camera_reason",
+ "value": "使用相机"
+ }
]
}
3. API
[!TIP] "ohos Support"列为 yes 表示 ohos 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
| Name | Description | Type | Input | Output | ohos Support |
|---|---|---|---|---|---|
| FlutterBarcodeScanner.getBarcodeStreamReceiver | 返回连续的扫描结果,直到用户取消操作 | function | String lineColor, String cancelButtonText, bool isShowFlashIcon, ScanMode scanMode | Stream? | yes |
| FlutterBarcodeScanner.scanBarcode | 扫码成功后返回扫码结果,并关闭摄像头 | function | String lineColor, String cancelButtonText, bool isShowFlashIcon, ScanMode scanMode | Future | yes |
4. 属性
[!TIP] "ohos Support"列为 yes 表示 ohos 平台支持该属性;no 则表示不支持;partially 表示部分支持。使用方法跨平台一致,效果对标 iOS 或 Android 的效果。
Parameters
| Name | Description | Type | ohos Support |
|---|---|---|---|
| lineColor | 十六进制颜色,设置扫描线的颜色 | String | yes |
| cancelButtonText | 设置取消按钮的文本文字 | String | yes |
| isShowFlashIcon | 用于显示或隐藏闪光图标 | bool | yes |
| scanMode | 一个枚举类型,用于设置扫描类型 | ScanMode | yes |
5. 遗留问题
6. 其他
7. 开源协议
本项目基于 The MIT License (MIT) ,请自由地享受和参与开源。