You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code snippet below shows the simplest implementation of a **function** that will initialize and launch the Barcode Scanner. Please note that in order to use the Barcode Scanner, a **valid license must be defined in the code**.
const result = await BarcodeScanner.launch(config);
76
-
if(result.status == EnumResultStatus.finished){
77
-
// handle the result
78
-
}
79
-
}
80
-
```
81
-
82
-
The above function can be triggered on any event, like when the app starts, on a button click, or more. Once the barcode scanner is launched, a barcode scanning interface opens - allowing the user to point at any barcode with the phone camera in order to read the barcode(s). Once the scan is complete, the interface closes and the result is returned.
83
-
84
-
> [!TIP]
85
-
> The Barcode Scanner is able to operate in a *single scan* mode or a *multiple scan* mode. In *single scan* mode, the barcode scanner can only capture one barcode at a time, even if there are multiple barcodes in the same frame or within the same view. In order to read multiple barcodes in the same frame or view, the barcode scanner needs to be in *multiple scan* mode.
86
-
>
87
-
> The scanning mode is determined by the `scanningMode` parameter of [`BarcodeScannerConfig`](api-reference/barcode-scanner/barcode-scanner-config.md). To use single scan mode, set `scanningMode` to *single*. To use multiple scan mode, set `scanningMode` to *multiple*.
88
-
89
-
This next code snippet demonstrates a simple example on how to configure the `_launchBarcodeScanner` function in the full **main.dart** implementation.
66
+
Replace your **main.dart** with the following code:
90
67
91
68
```dart
92
69
import 'package:flutter/material.dart';
@@ -122,30 +99,22 @@ class _MyHomePageState extends State<MyHomePage> {
@@ -199,69 +168,40 @@ Also see it in the [BarcodeScanResult](api-reference/barcode-scanner/barcode-sca
199
168
The advantage of using the BarcodeScanner component is in the simplicity of its configuration. As we have shown above, it doesn't take much to get the BarcodeScanner up and running. However, there could be cases where you want to make some changes to the default UI or setup that the BarcodeScanner provides. In this section, we run through the different configuration options provided in the [BarcodeScannerConfig](api-reference/barcode-scanner/barcode-scanner-config.md) class.
200
169
201
170
```dart
202
-
const config = BarcodeScannerConfig(
203
-
204
-
///The license key required to initialize the BarcodeScanner.
205
-
license: "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", //The license string here grants a time-limited free trial which requires network connection to work.
206
-
207
-
///Sets the barcode format(s) to read.
208
-
///This value is a combination of EnumBarcodeFormat flags that determine which barcode types to read.
209
-
///For example, to scan QR codes and OneD codes,
210
-
///set the value to `EnumBarcodeFormat.BF_QR_CODE | EnumBarcodeFormat.BF_ONED`.
///Determines whether the torch (flashlight) button is visible in the scanning UI.
219
183
///Set to true to display the torch button, enabling users to turn the flashlight on/off. Default is true.
220
184
isTorchButtonVisible: true,
221
-
222
185
///Specifies if a beep sound should be played when a barcode is successfully detected.
223
186
///Set to true to enable the beep sound, or false to disable it. Default is false.
224
187
isBeepEnabled: false,
225
-
226
188
///Enables or disables the auto-zoom feature during scanning.
227
189
///When enabled (true), the scanner will automatically zoom in to improve barcode detection. Default is false.
228
190
isAutoZoomEnabled: false,
229
-
230
191
///Determines whether the close button is visible on the scanner UI.
231
192
///This button allows users to exit the scanning interface. Default is true.
232
193
isCloseButtonVisible: true,
233
-
234
194
///Specifies whether the camera toggle button is displayed.
235
195
///This button lets users switch between available cameras (e.g., front and rear). Default is false.
236
196
isCameraToggleButtonVisible: false,
237
-
238
197
///Determines if a scanning laser overlay is shown on the scanning screen.
239
198
///This visual aid (scan laser) helps indicate the scanning line during barcode detection. Default is true.
240
-
isScanLaserVisible: true,
241
-
242
-
///Sets the scanning mode for the BarcodeScanner.
243
-
///The mode is defined by the EnumScanningMode and affects the scanning behavior. Default is `EnumScanningMode.single`.
244
-
scanningMode: EnumScanningMode.single,
245
-
246
-
///Defines the expected number of barcodes to be scanned.
247
-
///The scanning process will automatically stop when the number of detected barcodes reaches this count.
248
-
///Only available when `scanningMode` is set to `EnumScanningMode.multiple`. Default is 999.
249
-
expectedBarcodesCount: 999,
250
-
251
-
///Specifies the maximum number of consecutive stable frames to process before exiting scanning.
252
-
///A "stable frame" is one where no new barcode is detected.
253
-
///Only available when `scanningMode` is set to `EnumScanningMode.multiple`. Default is 10.
254
-
maxConsecutiveStableFramesToExit: 10,
255
-
256
-
///Specifies the template configuration for the BarcodeScanner.
257
-
///This can be either a file path or a JSON string that defines various scanning parameters.
258
-
///Default is undefined, which means the default template will be used.
259
-
templateFile: "JSON template string",
199
+
isScanLaserVisible: true
260
200
);
261
201
```
262
202
263
203
> [!TIP]
264
-
> Only a subset of the Barcode Reader parameters is exposed in the BarcodeScannerConfig class. In order to fully customize the performance of the BarcodeScanner instance, then we recommend using a JSON template to set the parameters, and then assign it to the BarcodeScanner instance using the `templateFile` parameter. To learn how to create your own JSON template, please refer to this [page](https://www.dynamsoft.com/barcode-reader/docs/core/programming/features/use-runtimesettings-or-templates.html?lang=objc,swift#json-template).
204
+
> Only a subset of the Barcode Reader parameters is exposed in the `BarcodeScannerConfig` class. In order to fully customize the performance of the BarcodeScanner instance, then we recommend using a JSON template to set the parameters, and then assign it to the BarcodeScanner instance using the `templateFile` parameter. To learn how to create your own JSON template, please refer to this [page](https://www.dynamsoft.com/barcode-reader/docs/core/programming/features/use-runtimesettings-or-templates.html?lang=objc,swift#json-template).
265
205
266
206
## Run the Project
267
207
@@ -291,16 +231,14 @@ Once the pods are installed, *Runner.xcworkspace* should now be generated in the
291
231
292
232
### Android
293
233
294
-
#### Camera Permissions
295
-
296
-
When using the Ready-To-Use BarcodeScanner API, **there is no need to configure the camera permissions for Android via the [`PermissionUtil`]({{ site.dcv_flutter_api }}utility/permission-util.html) class**. That is because the BarcodeScanner API takes care of these permissions internally, saving you the trouble.
297
-
298
234
#### Deploying to Device
299
235
300
-
Go to the project folder, open a new terminal and run the following command:
236
+
Go to the project root folder, open a new terminal and run the following command:
301
237
302
238
```bash
303
-
flutter run -d <DEVICE_ID>
239
+
flutter run
240
+
# or
241
+
flutter run -d <your_device_id>
304
242
```
305
243
306
244
You can get the IDs of all connected (physical) devices by running the command `flutter devices`.
@@ -311,8 +249,8 @@ The full sample code is available [here](https://github.com/Dynamsoft/barcode-re
311
249
312
250
## License
313
251
314
-
You can request a 30-day trial license via the [Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github&package=mobile)portal.
252
+
You can request a 30-day trial license via the [Request Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github&package=mobile)link.
0 commit comments