Skip to content

Commit ea35c99

Browse files
Updating guides
1 parent e38c991 commit ea35c99

File tree

5 files changed

+175
-219
lines changed

5 files changed

+175
-219
lines changed

programming/android/user-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class MainActivity : AppCompatActivity() {
244244
> [!Note]
245245
>
246246
> - The license string here grants a time-limited free trial which requires network connection to work.
247-
> - You can request a 30-day trial license via the [Request a Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=ios){:target="_blank"} link.
247+
> - You can request a 30-day trial license via the [Request a Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=android){:target="_blank"} link.
248248
> - If you download the <a href="https://www.dynamsoft.com/barcode-reader/downloads/?utm_source=docs#mobile" target="_blank">Installation Package</a>, it comes with a 30-day trial license by default.
249249
250250
### Step 5: Implementing the Barcode Scanner

programming/flutter/driver-license-user-guide.md

Lines changed: 69 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,20 @@ noTitleIndex: true
1010

1111
# Driver License Scanner Integration Guide
1212

13-
This guide will focus on the specific use case of scanning driver licenses to quickly retrieve one's ID info. Similar to the [Foundational Integration Guide](foundational-user-guide.md), this guide will utilize the [`Capture Vision Foundational API`]({{ site.dcv_flutter_api }}) to get the driver license scanner up and running.
14-
15-
> [!NOTE]
16-
> The Driver License Scanner is composed of two foundational Dynamsoft products - the [Dynamsoft Barcode Reader](https://www.dynamsoft.com/barcode-reader/sdk-mobile/) and the Dynamsoft Code Parser. The Barcode Reader is responsible for capturing and decoding the PDF417 barcodes of the driver licenses. Afterwards, the barcode result needs to be parsed into human-readable fields, which is where the Code Parser comes into play.
13+
This guide walks you through integrating a Driver License Scanner to quickly extract ID information from driver licenses.
1714

1815
## Supported Driver License Types
1916

20-
Driver licenses come with a PDF417 barcode (usually on the back) that encodes the holder's information. These driver licenses can come in different formats, which means different ways that the information is encoded into the barcode, or even the type of information that is encoded.
17+
Most driver licenses include a PDF417 barcode (usually on the back) that encodes personal information. Different regions use different formats, meaning the contained fields and encoding structure can vary.
2118

2219
### AAMVA Driver License
2320

24-
AAMVA - the American Association of Motor Vehicle Administrators - defines the standard that the majority of North American driver licenses need to adhere to. You can learn more about AAMVA on their [website](https://www.aamva.org/).
25-
26-
All versions of the AAMVA DL/ID specification (2000, 2003, 2005, 2009, 2010, 2011, 2012, 2013, 2016) are supported by the Dynamsoft Barcode Reader.
21+
The American Association of Motor Vehicle Administrators (AAMVA) defines the standard used across most North American driver licenses.
22+
All AAMVA DL/ID specification versions (2000–2016) are supported.
2723

2824
### South Africa Driver License
2925

30-
Support for South African driver licenses is limited - which means that the library is able to extract only a portion of the personal info that is encoded onto the driver license. Parsing of the full info from the driver license will come in a future version of the library.
26+
South African driver license barcodes are partially supported. [View supported fields]({{ site.code_types }}za-dl.html).
3127

3228
## System Requirements
3329

@@ -41,56 +37,29 @@ Support for South African driver licenses is limited - which means that the libr
4137
* Supported ABI: arm64 and x86_64
4238
* Development Environment: Xcode 13+ (Xcode 14.1+ recommended)
4339

44-
> [!TIP]
45-
> If you are downloading Xcode or Android Studio for the first time, please remember to also install the command-line tools.
46-
47-
> [!NOTE]
48-
> Please note that the sample projects that we offer were last tested with Flutter 3.35.7
49-
50-
## Including the Library
40+
## Adding the Library
5141

52-
Run the following command in the root directory of your flutter project to add `dynamsoft_barcode_reader_bundle_flutter` to the dependencies:
42+
Run the following in your project root:
5343

5444
```bash
5545
flutter pub add dynamsoft_barcode_reader_bundle_flutter
56-
```
57-
58-
Then run the following command to install all the dependencies:
59-
60-
```bash
6146
flutter pub get
6247
```
6348

6449
> [!NOTE]
65-
> Including the `dynamsoft_barcode_reader_bundle_flutter` library will also include the `dynamsoft_capture_vision_flutter` library, which will be the one that is actually imported and used.
50+
> Adding `dynamsoft_barcode_reader_bundle_flutter` automatically includes `dynamsoft_capture_vision_flutter`, which is the library you'll interact with directly.
6651
6752
## Building the Driver License Scanner Widget
6853

69-
Now that the package is added, it's time to start building the Driver License Scanner widget. Unlike the default implementation of the Barcode Reader that is explored in the other guides, building the driver license scanner requires a few more steps and classes to be implemented to fully represent the parsed result that is produced by the library.
70-
71-
These steps include importing the library, implementing the scanner page, creating the *DriverLicenseScanResult* class, and then putting them all together in `main.dart`.
72-
73-
### Importing the Library
74-
75-
To use the Capture Vision API, please import `dynamsoft_capture_vision_flutter` into the three files that we will be implementing (`main.dart`/`scan_page.dart`/`driver_license_scan_result.dart`):
54+
The driver license workflow includes:
7655

77-
```dart
78-
import 'package:dynamsoft_capture_vision_flutter/dynamsoft_capture_vision_flutter.dart';
79-
```
56+
- Implementing the scan page
57+
- Defining the result extraction APIs (e.g., `DriverLicenseScanResult`, `DriverLicenseData`)
58+
- Invoking the scanner from main.dart
8059

8160
### Create the Scan Page
8261

83-
Let's tackle the first and main component, the `ScannerPage` class which will be implemented in `scan_page.dart`. In order to implement the full driver license scanner workflow, the following needs to be done in order:
84-
85-
- Define a valid license via the [`LicenseManager`]({{ site.dcv_flutter_api }}license/license-manager.html)
86-
- Initialize the [`CameraEnhancer`]({{ site.dce_flutter_api }}camera-enhancer.html) object
87-
- Initialize the [`CaptureVisionRouter`]({{ site.dcv_flutter_api }}capture-vision-router/capture-vision-router.html) object
88-
- Bind the `CameraEnhancer` object to the `CaptureVisionRouter` object
89-
- Register a [`CapturedResultReceiver`]({{ site.dcv_flutter_api }}capture-vision-router/captured-result-receiver.html) object to listen for parsed driver license barcode results via the callback function [`onParsedResultsReceived`]({{ site.dcv_flutter_api }}capture-vision-router/captured-result-receiver.html#onparsedresultsreceived)
90-
- Open the camera
91-
- Start scanning via the [`startCapturing`]({{ site.dcv_flutter_api }}capture-vision-router/capture-vision-router.html#startcapturing) method while being configured to the `ReadDriversLicense` template.
92-
93-
The code snippet below shows the simplest implementation of *ScannerPage* that will set up and launch the Driver License Scanner. Please note that in order to use the Driver License Scanner, a **valid license must be defined in the code**.
62+
Create scan_page.dart and insert the full workflow:
9463

9564
```dart
9665
import 'package:dynamsoft_capture_vision_flutter/dynamsoft_capture_vision_flutter.dart';
@@ -106,27 +75,35 @@ class ScannerPage extends StatefulWidget {
10675
}
10776
10877
class _ScannerPageState extends State<ScannerPage> with RouteAware {
78+
// Create the CaptureVisionRouter instance. The CaptureVisionRouter is the class for managing the barcode scanning process.
10979
final CaptureVisionRouter _cvr = CaptureVisionRouter.instance;
80+
// Create the camera instance
11081
final CameraEnhancer _camera = CameraEnhancer.instance;
11182
final String _templateName = "ReadDriversLicense";
83+
// Define the result receiver for receiving the captured results.
11284
late final CapturedResultReceiver _receiver = CapturedResultReceiver()
11385
..onParsedResultsReceived = (ParsedResult result) async {
11486
if (result.items?.isNotEmpty ?? false) {
87+
// Stop capturing when dealing with the results.
11588
_cvr.stopCapturing();
89+
// Transfer the parsed result into driver license format data.
11690
final data = DriverLicenseData.fromParsedResultItem(result.items![0]);
11791
if (data != null) {
11892
final scanResult = DriverLicenseScanResult(resultStatus: EnumResultStatus.finished, data: data);
11993
Navigator.pop(context, scanResult);
12094
} else {
121-
_cvr.startCapturing(_templateName); // restart capturing
95+
// If data == null, restart capturing
96+
_cvr.startCapturing(_templateName);
12297
}
12398
}
12499
};
125100
126101
@override
127102
void initState() {
128103
super.initState();
104+
// Request camera permission
129105
PermissionUtil.requestCameraPermission();
106+
// A valid license is required.
130107
LicenseManager.initLicense('DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9').then((data) {
131108
final (isSuccess, message) = data;
132109
if (!isSuccess) {
@@ -137,10 +114,14 @@ class _ScannerPageState extends State<ScannerPage> with RouteAware {
137114
}
138115
139116
void initSdk() async {
117+
// Bind the Camera instance with the CaptureVisionRouter instance.
140118
await _cvr.setInput(_camera);
119+
// Bind the result receiver with the CaptureVisionRouter instance.
141120
_cvr.addResultReceiver(_receiver);
121+
// Open the camera
142122
_camera.open();
143123
try {
124+
// Start the capturing process.
144125
await _cvr.startCapturing(_templateName);
145126
} catch (e) {
146127
Navigator.of(context).pop(
@@ -155,6 +136,7 @@ class _ScannerPageState extends State<ScannerPage> with RouteAware {
155136
@override
156137
void dispose() {
157138
super.dispose();
139+
// Stop capturing, close the camera, and remove the result receiver when disposing.
158140
_cvr.stopCapturing();
159141
_camera.close();
160142
_cvr.removeResultReceiver(_receiver);
@@ -184,18 +166,19 @@ class _ScannerPageState extends State<ScannerPage> with RouteAware {
184166

185167
> [!NOTE]
186168
>
187-
> - `DriverLicenseData.fromParsedResultItem()` is a helper function to convert a [`ParsedResultItem`]({{ site.dcp_flutter_api }}parsed-result-item.html) into a more user-friendly structure (`DriverLicenseData`). You can get the source code from [driver_license_scan_result.dart](https://github.com/Dynamsoft/barcode-reader-flutter-samples/blob/main/ScanDriversLicense/lib/driver_license_scan_result.dart).
188169
>- The license string here grants a time-limited free trial which requires network connection to work.
189-
>- You can request a 30-day trial license via the [Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=mobile) portal.
170+
>- You can request a 30-day trial license via the [Request a Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=flutter){:target="_blank"} link.
190171
191-
### Define the Result Classes and Related APIs
172+
Related APIs:
192173

193-
The next step in building this app is to create the `DriverLicenseScanResult` class which will be used to represent the parsed information that is output by the library. **For the full implementation of this class, please refer to [*driver_license_scan_result.dart*](https://github.com/Dynamsoft/barcode-reader-flutter-samples/blob/main/ScanDriversLicense/lib/driver_license_scan_result.dart). Here is a quick breakdown of the `DriverLicenseScanResult` class:
174+
- [`LicenseManager`]({{ site.dcv_flutter_api }}license/license-manager.html) - licensing.
175+
- [`CameraEnhancer`]({{ site.dce_flutter_api }}camera-enhancer.html) - camera operations
176+
- [`CaptureVisionRouter`]({{ site.dcv_flutter_api }}capture-vision-router/capture-vision-router.html) - manages the scanning workflow
177+
- [`CapturedResultReceiver`]({{ site.dcv_flutter_api }}capture-vision-router/captured-result-receiver.html) - receives processed results
194178

195-
- `resultStatus` represents whether the result was produced successfully, if the scan operation was cancelled, or if an error occurred during the scanning process.
196-
- `data` is a `DriverLicenseData` object that represents the parsed information as different string fields which can then be accessed via these key fields and presented to the user in a friendly manner.
197-
- `DriverLicenseData` is created from a [`ParsedResultItem`]({{ site.dcp_flutter_api }}parsed-result-item.html) object via the `fromParsedResultItem()` function that is defined in the `DriverLicenseData` class.
198-
- `errorString` is the error message that is produced should the `resultStatus` be `exception`.
179+
### Define Result Models
180+
181+
Create `driver_license_scan_result.dart` and include the data structures used to represent parsed driver license fields.
199182

200183
```dart
201184
import 'package:dynamsoft_capture_vision_flutter/dynamsoft_capture_vision_flutter.dart';
@@ -207,8 +190,11 @@ enum EnumResultStatus {
207190
}
208191
209192
class DriverLicenseScanResult {
193+
// Represents whether the result was produced successfully, if the scan operation was cancelled, or if an error occurred during the scanning process.
210194
EnumResultStatus resultStatus;
195+
// When the resultStatus is "exception". You will receive the error message here.
211196
String? errorString = "";
197+
// A DriverLicenseData object that represents the parsed information as different string fields. Created from a ParsedResultItem.
212198
DriverLicenseData? data;
213199
DriverLicenseScanResult({
214200
required this.resultStatus,
@@ -315,9 +301,9 @@ class DriverLicenseData {
315301
}
316302
```
317303

318-
### Direct From the User Page to the Scan Page
304+
### Navigating to Scan Page
319305

320-
Now that the main Scanner widget and the `DriverLicenseScanResult` class are implemented, it's time to bring them together in the *main.dart* of the project. For the full implementation of *main.dart*, please see the code below:
306+
Add navigation logic in `main.dart` to trigger the scanner and display results.
321307

322308
```dart
323309
import 'package:flutter/material.dart';
@@ -398,21 +384,16 @@ class _MyHomePageState extends State<MyHomePage> {
398384
}
399385
```
400386

401-
## Customize the Driver License Scanner
402-
403-
Even though the Driver License Scanner comes with a template that is optimized for the typical driver license scanning scenario, there could be situations that require a different approach in order to get handled properly. The Driver License Scanner comes with a wide range of customizations, whether it is UI related, performance related, or a mix of both.
387+
### Customize the Driver License Scanner (Optional)
404388

405-
In this next section we will explore one of the ways in which the Driver License Scanner can be customized - specifying a scan region.
389+
Although the Driver License Scanner template is optimized for common scenarios, you may customize performance or UI behavior as needed.
406390

407-
### Specify the Scan Region
391+
#### Specify the Scan Region
408392

409-
You can limit the scan region of the library so that it doesn't exhaust resources trying to read from the entire image or frame.
393+
Restricting the scan region can reduce processing time and avoid reading unwanted areas:
410394

411395
```dart
412-
final CameraEnhancer _camera = CameraEnhancer.instance;
413-
414396
void initSdk() async {
415-
//......
416397
final scanRegion = DSRect(left: 0.1, top: 0.4, right: 0.9, bottom: 0.6, measuredInPercentage: true);
417398
_camera.setScanRegion(scanRegion);
418399
}
@@ -422,40 +403,50 @@ void initSdk() async {
422403

423404
### iOS
424405

425-
Before the project can be deployed to a *iOS* device, the camera permissions and the developer signature must first be set. To add the camera permissions to the iOS portion of the app, we recommend first installing the **pods** dependencies to generate the **.xcworkspace** project under the ios folder (`ios/Runner.xcworkspace`). Please run the following commands from the root directory:
426-
427-
```bash
428-
cd ios/
429-
pod install --repo-update
430-
```
406+
1. Install CocoaPods dependencies
431407

432-
#### Camera Permissions
408+
Before the project can be deployed to a *iOS* device, the camera permissions and the developer signature must first be set. To add the camera permissions to the iOS portion of the app, we recommend first installing the **pods** dependencies to generate the **.xcworkspace** project under the ios folder (`ios/Runner.xcworkspace`). Please run the following commands from the root directory:
433409

434-
Once the pods are installed, *Runner.xcworkspace* should now be generated in the *ios* folder. To add the camera permissions, open the generated *Runner.xcworkspace* and navigate to the *Info* section of the project settings. Then you must add the "Privacy - Camera Usage Description" key to the list (where you can also assign a string message to show in the alert box).
410+
```bash
411+
cd ios/
412+
pod install --repo-update
413+
```
435414

436-
#### Deploying to Device
415+
2. Configure the project in Xcode
437416

438-
In order to deploy the app to a iOS device, we recommend doing it via Xcode by using the `Runner.xcworkspace` project that was generated when the pods were installed. Since the camera permissions are taken care of, all you need to do is properly configure the *Signing & Capabilities* section of the project settings. Should the iOS device be connected to the computer, you can now run and deploy the app to the device.
417+
Open Runner.xcworkspace in Xcode and:
439418

440-
If everything is set up correctly, you should see the app running on your device.
419+
- Add **Privacy – Camera Usage Description** under **Project → Info**
420+
- Configure **Signing & Capabilities**
421+
- Connect your device and run the project
441422

442423
### Android
443424

444-
Go to the project folder, open a new terminal and run the following command:
425+
Run the app:
426+
427+
```bash
428+
flutter run
429+
```
430+
431+
Run on a specific device:
445432

446433
```bash
447434
flutter run -d <DEVICE_ID>
448435
```
449436

450-
You can get the IDs of all connected (physical) devices by running the command `flutter devices`.
437+
List devices:
438+
439+
```bash
440+
flutter devices
441+
```
451442

452443
## Full Sample Code
453444

454445
The full sample code is available [here](https://github.com/Dynamsoft/barcode-reader-flutter-samples/tree/main/ScanDriversLicense).
455446

456447
## License
457448

458-
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.
449+
You can request a 30-day trial license via the [Request a Trial License](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=guide&package=mobile){:target="_blank"} link.
459450

460451
## Support
461452

0 commit comments

Comments
 (0)