flutter_barcode_scanner_ohos
flutter_barcode_scanner_ohos is a plugin for Flutter apps that adds barcode scanning support on ohos.
How to use ?
To use on ohos, you will need to add the camera permission in module.json5.
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"
+ }
+ }
]
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"
+ }
]
}
Usage
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
One time scan
- You need to import the package first.
import 'package:flutter_barcode_scanner_ohos/flutter_barcode_scanner.dart';
- Then use the
scanBarcodemethod to access barcode scanning.
String barcodeScanRes = await FlutterBarcodeScanner.scanBarcode(
COLOR_CODE,
CANCEL_BUTTON_TEXT,
isShowFlashIcon,
scanMode);
Here in scanBarcode,
COLOR_CODE is hex-color which is the color of line in barcode overlay you can pass color of your choice,
CANCEL_BUTTON_TEXT is a text of cancel button on screen you can pass text of your choice and language,
isShowFlashIcon is bool value used to show or hide the flash icon,
scanMode is a enum in which user can pass any of { QR, BARCODE, DEFAULT }, if nothing is passed it will consider a default value which will be QR.
It shows the graphics overlay like for barcode and QR.
NOTE: Currently, scanMode is just to show the graphics overlay for barcode and QR. Any of this mode selected will scan both QR and barcode.
Continuous scan
- If you need to scan barcodes continuously without closing camera use
FlutterBarcodeScanner.getBarcodeStreamReceiverparams will be same likeFlutterBarcodeScanner.scanBarcodee.g.
FlutterBarcodeScanner.getBarcodeStreamReceiver("#ff6666", "Cancel", false, ScanMode.other)
.listen((barcode) {
/// barcode to be used
});