Skip to content

Commit e38c991

Browse files
Fixing bugs of Drivers License guide
1 parent a52e3c8 commit e38c991

File tree

2 files changed

+124
-25
lines changed

2 files changed

+124
-25
lines changed

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

Lines changed: 123 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ To use the Capture Vision API, please import `dynamsoft_capture_vision_flutter`
7878
import 'package:dynamsoft_capture_vision_flutter/dynamsoft_capture_vision_flutter.dart';
7979
```
8080

81-
### Implementing the Widget
81+
### Create the Scan Page
8282

8383
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:
8484

@@ -188,16 +188,134 @@ class _ScannerPageState extends State<ScannerPage> with RouteAware {
188188
>- The license string here grants a time-limited free trial which requires network connection to work.
189189
>- 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.
190190
191-
### Implementing the DriverLicenseScanResult Class
191+
### Define the Result Classes and Related APIs
192192

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*]([ScanDriversLicense/lib/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:
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:
194194

195195
- `resultStatus` represents whether the result was produced successfully, if the scan operation was cancelled, or if an error occurred during the scanning process.
196196
- `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.
197197
- `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.
198198
- `errorString` is the error message that is produced should the `resultStatus` be `exception`.
199199

200-
### Finalizing the App
200+
```dart
201+
import 'package:dynamsoft_capture_vision_flutter/dynamsoft_capture_vision_flutter.dart';
202+
203+
enum EnumResultStatus {
204+
finished,
205+
cancelled,
206+
error,
207+
}
208+
209+
class DriverLicenseScanResult {
210+
EnumResultStatus resultStatus;
211+
String? errorString = "";
212+
DriverLicenseData? data;
213+
DriverLicenseScanResult({
214+
required this.resultStatus,
215+
this.errorString,
216+
this.data,
217+
});
218+
}
219+
220+
class DriverLicenseData {
221+
String documentType;
222+
String? name;
223+
String? state; //For AAMVA_DL_ID
224+
String? stateOrProvince; //For AAMVA_DL_ID_WITH_MAG_STRIPE
225+
String? initials; //For SOUTH_AFRICA_DL
226+
String? city; //For AAMVA_DL_ID, AAMVA_DL_ID_WITH_MAG_STRIPE
227+
String? address; //For AAMVA_DL_ID, AAMVA_DL_ID_WITH_MAG_STRIPE
228+
String? idNumber; //For SOUTH_AFRICA_DL
229+
String? idNumberType; //For SOUTH_AFRICA_DL
230+
String? licenseNumber;
231+
String? licenseIssueNumber; //For SOUTH_AFRICA_DL
232+
String? issuedDate;
233+
String? expirationDate;
234+
String? birthDate;
235+
String? sex;
236+
String? height; //For AAMVA_DL_ID, SOUTH_AFRICA_DL
237+
String? issuedCountry; //For AAMVA_DL_ID, SOUTH_AFRICA_DL
238+
String? vehicleClass; //For AAMVA_DL_ID
239+
String? driverRestrictionCodes; //For SOUTH_AFRICA_DL
240+
DriverLicenseData({
241+
required this.documentType
242+
});
243+
244+
Map<String, String> toMap() {
245+
return {
246+
'documentType': documentType,
247+
if (name != null) 'name': name!,
248+
if (state != null) 'state': state!,
249+
if (stateOrProvince != null) 'stateOrProvince': stateOrProvince!,
250+
if (initials != null) 'initials': initials!,
251+
if (city != null) 'city': city!,
252+
if (address != null) 'address': address!,
253+
if (idNumber != null) 'idNumber': idNumber!,
254+
if (idNumberType != null) 'idNumberType': idNumberType!,
255+
if (licenseNumber != null) 'licenseNumber': licenseNumber!,
256+
if (licenseIssueNumber != null) 'licenseIssueNumber': licenseIssueNumber!,
257+
if (issuedDate != null) 'issuedDate': issuedDate!,
258+
if (expirationDate != null) 'expirationDate': expirationDate!,
259+
if (birthDate != null) 'birthDate': birthDate!,
260+
if (sex != null) 'sex': sex!,
261+
if (height != null) 'height': height!,
262+
if (issuedCountry != null) 'issuedCountry': issuedCountry!,
263+
if (vehicleClass != null) 'vehicleClass': vehicleClass!,
264+
if (driverRestrictionCodes != null) 'driverRestrictionCodes': driverRestrictionCodes!,
265+
};
266+
}
267+
268+
static DriverLicenseData? fromParsedResultItem(ParsedResultItem item) {
269+
var codeType = item.codeType;
270+
var parsedFields = item.parsedFields;
271+
if(parsedFields.isEmpty) {
272+
return null;
273+
}
274+
var data = DriverLicenseData(documentType: codeType);
275+
if(codeType == 'AAMVA_DL_ID') {
276+
data.name = parsedFields['fullName']?.value ??
277+
"${parsedFields['givenName']?.value ?? parsedFields['givenName']?.value ??""} ${parsedFields['lastName']?.value ?? ''}";
278+
data.city = parsedFields['city']?.value;
279+
data.state = parsedFields['jurisdictionCode']?.value;
280+
data.address = "${parsedFields['street_1']?.value??""} ${parsedFields['street_2']?.value??""}";
281+
data.licenseNumber = parsedFields['licenseNumber']?.value;
282+
data.issuedDate = parsedFields['issuedDate']?.value;
283+
data.expirationDate = parsedFields['expirationDate']?.value;
284+
data.birthDate = parsedFields['birthDate']?.value;
285+
data.height = parsedFields['height']?.value;
286+
data.sex = parsedFields['sex']?.value;
287+
data.issuedCountry = parsedFields['issuedCountry']?.value;
288+
data.vehicleClass = parsedFields['vehicleClass']?.value;
289+
} else if(codeType == 'AAMVA_DL_ID_WITH_MAG_STRIPE') {
290+
data.name = parsedFields['name']?.value;
291+
data.city = parsedFields['city']?.value;
292+
data.stateOrProvince = parsedFields['stateOrProvince']?.value;
293+
data.address = parsedFields['address']?.value;
294+
data.licenseNumber = parsedFields['DLorID_Number']?.value;
295+
data.expirationDate = parsedFields['expirationDate']?.value;
296+
data.birthDate = parsedFields['birthDate']?.value;
297+
data.height = parsedFields['height']?.value;
298+
data.sex = parsedFields['sex']?.value;
299+
} else if(codeType == 'SOUTH_AFRICA_DL') {
300+
data.name = parsedFields['surname']?.value;
301+
data.idNumber = parsedFields['idNumber']?.value;
302+
data.idNumberType = parsedFields['idNumberType']?.value;
303+
data.licenseNumber = parsedFields['idNumber']?.value ?? parsedFields['licenseNumber']?.value;
304+
data.licenseIssueNumber = parsedFields['licenseIssueNumber']?.value;
305+
data.initials = parsedFields['initials']?.value;
306+
data.issuedDate = parsedFields['licenseValidityFrom']?.value;
307+
data.expirationDate = parsedFields['licenseValidityTo']?.value;
308+
data.birthDate = parsedFields['birthDate']?.value;
309+
data.sex = parsedFields['gender']?.value;
310+
data.issuedCountry = parsedFields['idIssuedCountry']?.value;
311+
data.driverRestrictionCodes = parsedFields['driverRestrictionCodes']?.value;
312+
}
313+
return data;
314+
}
315+
}
316+
```
317+
318+
### Direct From the User Page to the Scan Page
201319

202320
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:
203321

@@ -323,19 +441,6 @@ If everything is set up correctly, you should see the app running on your device
323441

324442
### Android
325443

326-
#### Camera Permissions
327-
328-
On Android, permission to use the camera must be set in the code as such:
329-
330-
```dart
331-
PermissionUtil.requestCameraPermission();
332-
```
333-
334-
> [!NOTE]
335-
> This is done via the [`PermissionUtil`]({{ site.dcv_flutter_api }}utility/permission-util.html) class. Please note that the code snippets in the previous sections contain this line in order to make the app run successfully.
336-
337-
#### Deploying to Device
338-
339444
Go to the project folder, open a new terminal and run the following command:
340445

341446
```bash
@@ -344,12 +449,6 @@ flutter run -d <DEVICE_ID>
344449

345450
You can get the IDs of all connected (physical) devices by running the command `flutter devices`.
346451

347-
#### iOS
348-
349-
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.
350-
351-
If everything is set up correctly, you should see the app running on your device.
352-
353452
## Full Sample Code
354453

355454
The full sample code is available [here](https://github.com/Dynamsoft/barcode-reader-flutter-samples/tree/main/ScanDriversLicense).
@@ -360,4 +459,4 @@ You can request a 30-day trial license via the [Trial License](https://www.dynam
360459

361460
## Support
362461

363-
https://www.dynamsoft.com/company/contact/
462+
[https://www.dynamsoft.com/company/contact/](https://www.dynamsoft.com/company/contact/)

programming/flutter/foundational-user-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,4 @@ You can request a 30-day trial license via the [Trial License](https://www.dynam
327327

328328
## Support
329329

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

0 commit comments

Comments
 (0)