Skip to content

Commit 1b5e09e

Browse files
Merge pull request #375 from dynamsoft-docs/preview
update to internal commit 2ccb3da7
2 parents 56e6c99 + fba622e commit 1b5e09e

File tree

1 file changed

+27
-89
lines changed

1 file changed

+27
-89
lines changed

programming/flutter/user-guide.md

Lines changed: 27 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,7 @@ import 'package:dynamsoft_barcode_reader_bundle_flutter/dynamsoft_barcode_reader
6363

6464
### Quick Start
6565

66-
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**.
67-
68-
```dart
69-
import 'package:dynamsoft_barcode_reader_bundle_flutter/dynamsoft_barcode_reader_bundle_flutter.dart';
70-
71-
void _launchBarcodeScanner() async{
72-
var config = BarcodeScannerConfig(
73-
license: 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9',
74-
);
75-
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:
9067

9168
```dart
9269
import 'package:flutter/material.dart';
@@ -122,30 +99,22 @@ class _MyHomePageState extends State<MyHomePage> {
12299
void _launchBarcodeScanner() async{
123100
var config = BarcodeScannerConfig(
124101
license: 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9',
125-
scanningMode: 'single', // configuring the Barcode Scanner into single scan mode
102+
/// You can switch between single & multiple here.
103+
/// Single mode can scan multiple barcodes at once but only returns one result.
104+
/// Multiple mode returns multiple results.
105+
scanningMode: EnumScanningMode.single,
126106
);
127107
BarcodeScanResult result = await BarcodeScanner.launch(config);
108+
128109
if(result.status == EnumResultStatus.finished){
129110
setState(() {
130-
if (barcodeScanResult.status == EnumResultStatus.canceled) {
111+
if (result.status == EnumResultStatus.canceled) {
131112
_displayString = "Scan canceled";
132-
} else if (barcodeScanResult.status == EnumResultStatus.exception) {
133-
_displayString = "ErrorCode: ${barcodeScanResult.errorCode}\n\nErrorString: ${barcodeScanResult.errorMessage}";
113+
} else if (result.status == EnumResultStatus.exception) {
114+
_displayString = "ErrorCode: ${result.errorCode}\n\nErrorString: ${result.errorMessage}";
134115
} else {
135-
//EnumResultStatus.finished
136-
if (scanningMode == EnumScanningMode.single) {
137-
var barcode = barcodeScanResult.barcodes![0];
138-
_displayString = "Format: ${barcode!.formatString}\nText: ${barcode.text}";
139-
} else {
140-
// EnumScanningMode.multiple
141-
_displayString =
142-
"Barcodes count: ${barcodeScanResult.barcodes!.length}\n\n" +
143-
barcodeScanResult.barcodes!
144-
.map((barcode) {
145-
return "Format: ${barcode!.formatString}\nText: ${barcode.text}";
146-
})
147-
.join("\n\n");
148-
}
116+
var barcode = result.barcodes![0];
117+
_displayString = "Format: ${barcode!.formatString}\nText: ${barcode.text}";
149118
}
150119
});
151120
}
@@ -199,69 +168,40 @@ Also see it in the [BarcodeScanResult](api-reference/barcode-scanner/barcode-sca
199168
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.
200169

201170
```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`.
211-
barcodeFormats: EnumBarcodeFormat.BF_QR_CODE | EnumBarcodeFormat.BF_ONED,
212-
171+
var config = BarcodeScannerConfig(
172+
license: 'DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9',
173+
scanningMode: EnumScanningMode.single,
174+
///Defines the barcode formats.
175+
///For example: set the target barcode formats to OneD and QR.
176+
/// You have to 'package:dynamsoft_capture_vision_flutter/dynamsoft_capture_vision_flutter.dart' to use the EnumBarcodeFormat.
177+
barcodeFormats: EnumBarcodeFormat.oned | EnumBarcodeFormat.qrCode,
213178
///Defines the scanning area as a DSRect object where barcodes will be detected.
214179
///Only the barcodes located within this defined region will be processed.
215180
///Default is undefined, which means the full screen will be scanned.
216-
scanRegion: DSRect(top: 0.25, bottom: 0.75, left: 0.25, right: 0.75, measuredInPercentage: true), // scan the middle 50% of the screen
217-
181+
scanRegion: DSRect(top: 0.35, bottom: 0.65, left: 0.15, right: 0.85, measuredInPercentage: true),
218182
///Determines whether the torch (flashlight) button is visible in the scanning UI.
219183
///Set to true to display the torch button, enabling users to turn the flashlight on/off. Default is true.
220184
isTorchButtonVisible: true,
221-
222185
///Specifies if a beep sound should be played when a barcode is successfully detected.
223186
///Set to true to enable the beep sound, or false to disable it. Default is false.
224187
isBeepEnabled: false,
225-
226188
///Enables or disables the auto-zoom feature during scanning.
227189
///When enabled (true), the scanner will automatically zoom in to improve barcode detection. Default is false.
228190
isAutoZoomEnabled: false,
229-
230191
///Determines whether the close button is visible on the scanner UI.
231192
///This button allows users to exit the scanning interface. Default is true.
232193
isCloseButtonVisible: true,
233-
234194
///Specifies whether the camera toggle button is displayed.
235195
///This button lets users switch between available cameras (e.g., front and rear). Default is false.
236196
isCameraToggleButtonVisible: false,
237-
238197
///Determines if a scanning laser overlay is shown on the scanning screen.
239198
///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
260200
);
261201
```
262202

263203
> [!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).
265205
266206
## Run the Project
267207

@@ -291,16 +231,14 @@ Once the pods are installed, *Runner.xcworkspace* should now be generated in the
291231

292232
### Android
293233

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-
298234
#### Deploying to Device
299235

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:
301237

302238
```bash
303-
flutter run -d <DEVICE_ID>
239+
flutter run
240+
# or
241+
flutter run -d <your_device_id>
304242
```
305243

306244
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
311249

312250
## License
313251

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.
315253

316254
## Support
317255

318-
https://www.dynamsoft.com/company/contact/
256+
[https://www.dynamsoft.com/company/contact/](https://www.dynamsoft.com/company/contact/)

0 commit comments

Comments
 (0)