epassportnfc 0.0.3
epassportnfc: ^0.0.3 copied to clipboard
EPassport nfc.
example/lib/main.dart
import 'dart:convert';
import 'package:epassportnfc/epassportnfc.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
),
);
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
NFCResponse? datanfc;
String state = '';
@override
void initState() {
super.initState();
test();
}
void test() {
Epassportnfc.nfcStream.listen((NFCResponse event) {
print(event.status);
datanfc = event;
// if (event.status == 'WAITING') {
// showWaiting(context);
// }
state = event.status ?? '';
// if (event.status == 'SUCCESS') {
// Navigator.pop(context);
// datanfc = event;
// }
setState(() {});
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await Epassportnfc.nfc(passportNumberController.text,
birthDayNumberController.text, expireNumberController.text) ??
'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
TextEditingController passportNumberController = TextEditingController()
..text = '';
TextEditingController birthDayNumberController = TextEditingController()
..text = '';
TextEditingController expireNumberController = TextEditingController()
..text = '';
void showWaiting(BuildContext context) {
var alert = AlertDialog(
title: Text("NFC tag reader"),
content: Text("Hold your iPhone near an NFC enabled passport."),
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('EPassport'),
),
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(8),
child: TextField(
controller: passportNumberController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'CCCD',
hintText: 'CCCD'),
),
),
Padding(
padding: EdgeInsets.all(8),
child: TextField(
controller: birthDayNumberController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Ngày sinh',
hintText: 'Ngày sinh'),
),
),
Padding(
padding: EdgeInsets.all(8),
child: TextField(
controller: expireNumberController,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Ngày hết hạn',
hintText: 'Ngày hết hạn'),
),
),
ElevatedButton(
onPressed: () {
initPlatformState();
},
child: Text('Read nfc')),
Text(state),
if (datanfc?.status == 'SUCCESS' &&
datanfc != null &&
datanfc?.imageData != null)
Column(
children: [
Image.memory(base64Decode(datanfc?.imageData ?? '')),
Text(
'Fullname: ${datanfc?.firstName ?? ''} ${datanfc?.lastName}'),
Text('CCCD: ${datanfc?.personalNumber ?? ''}'),
Text('ngay sinh: ${datanfc?.dateOfBirth ?? ''}')
],
)
],
),
),
);
}
}