Name Last Update
..
.github Loading commit data...
android Loading commit data...
ios Loading commit data...
lib Loading commit data...
ohos Loading commit data...
.gitignore Loading commit data...
.metadata Loading commit data...
CHANGELOG.md Loading commit data...
LICENSE Loading commit data...
OAT.xml Loading commit data...
README.OpenHarmony.md Loading commit data...
README.OpenHarmony_CN.md Loading commit data...
README.md Loading commit data...
analysis_options.yaml Loading commit data...
pubspec.lock Loading commit data...
pubspec.yaml Loading commit data...

Template version: v0.0.1

flutter_barcode_scanner

This project is based on flutter_barcode_scanner.

1. Installation and Usage

1.1 Installation

Go to the project directory and add the following dependencies in pubspec.yaml

pubspec.yaml

...

dependencies:
  flutter_barcode_scanner_ohos:
    git: 
      url: https://gitcode.com/openharmony-sig/fluttertpc_flutter_barcode_scanner.git
      path: ohos

...

Execute Command

flutter pub get

1.2 Usage

For use cases ohos/example

2. Constraints

2.1 Compatibility

This document is verified based on the following versions:

  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;
  2. 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 Permission Requirements

2.2.1 Add permissions to the module.json5 file in the entry directory.

Open entry/src/main/module.json5 and add the following information:

...
"requestPermissions": [
+  {
+    "name": "ohos.permission.CAMERA",
+    "reason": "$string:camera_reason",
+    "usedScene": {
+      "abilities": [
+        "EntryAbility"
+      ],
+      "when":"inuse"
+    }
+  }
]

2.2.2 Add the reason for applying for the preceding permission to the entry directory.

Open entry/src/main/resources/base/element/string.json and add the following information:

...
{
  "string": [
+    {
+      "name": "camera_reason",
+      "value": "camera_reason"
+    }
  ]
}

3. API

[!TIP] If the value of ohos Support is yes, it means that the ohos platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.

Name Description Type Input Output ohos Support
FlutterBarcodeScanner.getBarcodeStreamReceiver Returns a continuous stream of barcode scans until the user cancels the operation function String lineColor, String cancelButtonText, bool isShowFlashIcon, ScanMode scanMode Stream? yes
FlutterBarcodeScanner.scanBarcode Scan with the camera until a barcode is identified, then return function String lineColor, String cancelButtonText, bool isShowFlashIcon, ScanMode scanMode Future yes

4. Properties

[!TIP] If the value of ohos Support is yes, it means that the ohos platform supports this property; no means the opposite; partially means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.

Parameters

Name Description Type ohos Support
lineColor is hex-color which is the color of line in barcode overlay you can pass color of your choice String yes
cancelButtonText is a text of cancel button on screen you can pass text of your choice and language String yes
isShowFlashIcon is bool value used to show or hide the flash icon bool yes
scanMode is a enum in which user can pass any of { QR, BARCODE, DEFAULT } ScanMode yes

5. Known Issues

6. Others

7. License

This project is licensed under The MIT License (MIT).