NFC Capture on Android
NFC capture on Android
Android has single method for starting NFC Capture while there are multiple options to start the NFC Capture on iOS.
If you're not capturing the NFC Data after the IDCapture, this process requires some parameters from the id itself.
All date formats must be in YYMMDD
.
For example, September 1st 1999
becomes 990901
.
Also you must stop the NFC listener on the dispose()
method of your widget. You can also achive this on the onFinishedCallback
parameter of startNFCListener
method of AndroidNFCCapture
class if you're calling this method from a stateless widget.
The example below uses statefull widget.
Future<void> stopNFCListener() async {
_nfcCapture.stopNFCListener();
}
Future<void> setNFCType() async {
_nfcCapture.setType("XXX_NF_0");
}
void initState() {
setNFCType();
super.initState();
}
void dispose() {
stopNFCListener();
super.dispose();
}
Starting the capture
OutlinedButton(
onPressed: () {
if (_dateOfBirth != "" &&
_expireDate != "" &&
_documentNo != "") {
_nfcCapture.startNFCListener(
birthDate: _dateOfBirth,
expireDate: _expireDate,
documentNo: _documentNo,
onFinishedCallback: (isCaptureCompleted) {
setState(() {
_isCompleted = isCaptureCompleted;
});
},
onErrorCallback: (errorString) {
// handle the read errors here
},
onScanStart: () {
// This callback will invoked when user shows an NFC tag
}
).catchError((err) {
// Handle the intialization errors here
});
}
},
child:
const Text("NVI Data Start (fields must be filled)"))
To upload you can call the upload method like this
OutlinedButton(
onPressed: () {
if (_isCompleted == false) {
return;
} else {
_nfcCapture.upload();
}
},
child: const Text("Upload (last step)"))