forked from ZeroPass/dmrtd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.dart
701 lines (609 loc) · 22.1 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// Created by Crt Vavros, copyright © 2022 ZeroPass. All rights reserved.
// ignore_for_file: prefer_adjacent_string_concatenation, prefer_interpolation_to_compose_strings
import 'package:expandable/expandable.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'dart:async';
import 'dart:typed_data';
import 'package:dmrtd/dmrtd.dart';
import 'package:dmrtd/extensions.dart';
import 'package:flutter/services.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:intl/intl.dart';
import 'package:logging/logging.dart';
class MrtdData {
EfCardAccess? cardAccess;
EfCardSecurity? cardSecurity;
EfCOM? com;
EfSOD? sod;
EfDG1? dg1;
EfDG2? dg2;
EfDG3? dg3;
EfDG4? dg4;
EfDG5? dg5;
EfDG6? dg6;
EfDG7? dg7;
EfDG8? dg8;
EfDG9? dg9;
EfDG10? dg10;
EfDG11? dg11;
EfDG12? dg12;
EfDG13? dg13;
EfDG14? dg14;
EfDG15? dg15;
EfDG16? dg16;
Uint8List? aaSig;
}
final Map<DgTag, String> dgTagToString = {
EfDG1.TAG : 'EF.DG1',
EfDG2.TAG : 'EF.DG2',
EfDG3.TAG : 'EF.DG3',
EfDG4.TAG : 'EF.DG4',
EfDG5.TAG : 'EF.DG5',
EfDG6.TAG : 'EF.DG6',
EfDG7.TAG : 'EF.DG7',
EfDG8.TAG : 'EF.DG8',
EfDG9.TAG : 'EF.DG9',
EfDG10.TAG : 'EF.DG10',
EfDG11.TAG : 'EF.DG11',
EfDG12.TAG : 'EF.DG12',
EfDG13.TAG : 'EF.DG13',
EfDG14.TAG : 'EF.DG14',
EfDG15.TAG : 'EF.DG15',
EfDG16.TAG : 'EF.DG16'
};
String formatEfCom(final EfCOM efCom) {
var str = "version: ${efCom.version}\n"
"unicode version: ${efCom.unicodeVersion}\n"
"DG tags:";
for(final t in efCom.dgTags) {
try {
str += " ${dgTagToString[t]!}";
}
catch (e) {
str += " 0x${t.value.toRadixString(16)}";
}
}
return str;
}
String formatMRZ(final MRZ mrz) {
return "MRZ\n"
" version: ${mrz.version}\n" +
" doc code: ${mrz.documentCode}\n" +
" doc No.: ${mrz.documentNumber}\n" +
" country: ${mrz.country}\n" +
" nationality: ${mrz.nationality}\n" +
" name: ${mrz.firstName}\n" +
" surname: ${mrz.lastName}\n" +
" gender: ${mrz.gender}\n" +
" date of birth: ${DateFormat.yMd().format(mrz.dateOfBirth) }\n" +
" date of expiry: ${DateFormat.yMd().format(mrz.dateOfExpiry) }\n" +
" add. data: ${mrz.optionalData}\n" +
" add. data: ${mrz.optionalData2}";
}
String formatDG15(final EfDG15 dg15) {
var str = "EF.DG15:\n"
" AAPublicKey\n"
" type: ";
final rawSubPubKey = dg15.aaPublicKey.rawSubjectPublicKey();
if(dg15.aaPublicKey.type == AAPublicKeyType.RSA) {
final tvSubPubKey = TLV.fromBytes(rawSubPubKey);
var rawSeq = tvSubPubKey.value;
if(rawSeq[0] == 0x00) {
rawSeq = rawSeq.sublist(1);
}
final tvKeySeq = TLV.fromBytes(rawSeq);
final tvModule = TLV.decode(tvKeySeq.value);
final tvExp = TLV.decode(tvKeySeq.value.sublist(tvModule.encodedLen));
str += "RSA\n"
" exponent: ${tvExp.value.hex()}\n"
" modulus: ${tvModule.value.hex()}";
}
else {
str += "EC\n SubjectPublicKey: ${rawSubPubKey.hex()}";
}
return str;
}
String formatProgressMsg(String message, int percentProgress) {
final p = (percentProgress/20).round();
final full = "🟢 " * p;
final empty = "⚪️ " * (5-p);
return message + "\n\n" + full + empty;
}
void main() {
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
print('${record.loggerName} ${record.level.name}: ${record.time}: ${record.message}');
});
runApp(MrtdEgApp());
}
class MrtdEgApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PlatformApp(
localizationsDelegates:[
DefaultMaterialLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
material: (_, __) => MaterialAppData(),
cupertino: (_, __) => CupertinoAppData(),
home: MrtdHomePage()
);
}
}
class MrtdHomePage extends StatefulWidget {
@override
// ignore: library_private_types_in_public_api
_MrtdHomePageState createState() => _MrtdHomePageState();
}
class _MrtdHomePageState extends State<MrtdHomePage> {
var _alertMessage = "";
final _log = Logger("mrtdeg.app");
var _isNfcAvailable = false;
var _isReading = false;
final _mrzData = GlobalKey<FormState>();
// mrz data
final _docNumber = TextEditingController();
final _dob = TextEditingController(); // date of birth
final _doe = TextEditingController(); // date of doc expiry
MrtdData? _mrtdData;
final NfcProvider _nfc = NfcProvider();
// ignore: unused_field
late Timer _timerStateUpdater;
final _scrollController = ScrollController();
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
_initPlatformState();
// Update platform state every 3 sec
_timerStateUpdater = Timer.periodic(Duration(seconds: 3), (Timer t) {
_initPlatformState();
});
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> _initPlatformState() async {
bool isNfcAvailable;
try {
NfcStatus status = await NfcProvider.nfcStatus;
isNfcAvailable = status == NfcStatus.enabled;
} on PlatformException {
isNfcAvailable = false;
}
// 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(() {
_isNfcAvailable = isNfcAvailable;
});
}
DateTime? _getDOBDate() {
if(_dob.text.isEmpty) {
return null;
}
return DateFormat.yMd().parse(_dob.text);
}
DateTime? _getDOEDate() {
if(_doe.text.isEmpty) {
return null;
}
return DateFormat.yMd().parse(_doe.text);
}
Future<String?> _pickDate(BuildContext context, DateTime firstDate, DateTime initDate, DateTime lastDate) async {
final locale = Localizations.localeOf(context);
final DateTime? picked = await showDatePicker(
context: context,
firstDate: firstDate,
initialDate: initDate,
lastDate: lastDate,
locale: locale
);
if(picked != null) {
return DateFormat.yMd().format(picked);
}
return null;
}
void _readMRTD() async {
try {
setState(() {
_mrtdData = null;
_alertMessage = "Waiting for Passport tag ...";
_isReading = true;
});
await _nfc.connect(iosAlertMessage: "Hold your phone near Biometric Passport");
final passport = Passport(_nfc);
setState(() {
_alertMessage = "Reading Passport ...";
});
_nfc.setIosAlertMessage("Trying to read EF.CardAccess ...");
final mrtdData = MrtdData();
try {
mrtdData.cardAccess = await passport.readEfCardAccess();
}
on PassportError {
//if (e.code != StatusWord.fileNotFound) rethrow;
}
_nfc.setIosAlertMessage("Trying to read EF.CardSecurity ...");
try {
mrtdData.cardSecurity = await passport.readEfCardSecurity();
}
on PassportError {
//if (e.code != StatusWord.fileNotFound) rethrow;
}
_nfc.setIosAlertMessage("Initiating session ...");
final bacKeySeed = DBAKeys(_docNumber.text, _getDOBDate()!, _getDOEDate()!);
await passport.startSession(bacKeySeed);
_nfc.setIosAlertMessage(formatProgressMsg("Reading EF.COM ...", 0));
mrtdData.com = await passport.readEfCOM();
_nfc.setIosAlertMessage(formatProgressMsg("Reading Data Groups ...", 20));
if(mrtdData.com!.dgTags.contains(EfDG1.TAG)) {
mrtdData.dg1 = await passport.readEfDG1();
}
if(mrtdData.com!.dgTags.contains(EfDG2.TAG)) {
mrtdData.dg2 = await passport.readEfDG2();
}
// To read DG3 and DG4 session has to be established with CVCA certificate (not supported).
// if(mrtdData.com!.dgTags.contains(EfDG3.TAG)) {
// mrtdData.dg3 = await passport.readEfDG3();
// }
// if(mrtdData.com!.dgTags.contains(EfDG4.TAG)) {
// mrtdData.dg4 = await passport.readEfDG4();
// }
if(mrtdData.com!.dgTags.contains(EfDG5.TAG)) {
mrtdData.dg5 = await passport.readEfDG5();
}
if(mrtdData.com!.dgTags.contains(EfDG6.TAG)) {
mrtdData.dg6 = await passport.readEfDG6();
}
if(mrtdData.com!.dgTags.contains(EfDG7.TAG)) {
mrtdData.dg7 = await passport.readEfDG7();
}
if(mrtdData.com!.dgTags.contains(EfDG8.TAG)) {
mrtdData.dg8 = await passport.readEfDG8();
}
if(mrtdData.com!.dgTags.contains(EfDG9.TAG)) {
mrtdData.dg9 = await passport.readEfDG9();
}
if(mrtdData.com!.dgTags.contains(EfDG10.TAG)) {
mrtdData.dg10 = await passport.readEfDG10();
}
if(mrtdData.com!.dgTags.contains(EfDG11.TAG)) {
mrtdData.dg11 = await passport.readEfDG11();
}
if(mrtdData.com!.dgTags.contains(EfDG12.TAG)) {
mrtdData.dg12 = await passport.readEfDG12();
}
if(mrtdData.com!.dgTags.contains(EfDG13.TAG)) {
mrtdData.dg13 = await passport.readEfDG13();
}
if(mrtdData.com!.dgTags.contains(EfDG14.TAG)) {
mrtdData.dg14 = await passport.readEfDG14();
}
if(mrtdData.com!.dgTags.contains(EfDG15.TAG)) {
mrtdData.dg15 = await passport.readEfDG15();
_nfc.setIosAlertMessage(formatProgressMsg("Doing AA ...", 60));
mrtdData.aaSig = await passport.activeAuthenticate(Uint8List(8));
}
if(mrtdData.com!.dgTags.contains(EfDG16.TAG)) {
mrtdData.dg16 = await passport.readEfDG16();
}
_nfc.setIosAlertMessage(formatProgressMsg("Reading EF.SOD ...", 80));
mrtdData.sod = await passport.readEfSOD();
setState(() {
_mrtdData = mrtdData;
});
setState(() {
_alertMessage = "";
});
_scrollController.animateTo(300.0,
duration: Duration(milliseconds: 500), curve: Curves.ease
);
}
on Exception catch(e) {
final se = e.toString().toLowerCase();
String alertMsg = "An error has occurred while reading Passport!";
if(e is PassportError) {
if(se.contains("security status not satisfied")) {
alertMsg = "Failed to initiate session with passport.\nCheck input data!";
}
_log.error("PassportError: ${e.message}");
}
else {
_log.error("An exception was encountered while trying to read Passport: $e");
}
if(se.contains('timeout')){
alertMsg = "Timeout while waiting for Passport tag";
}
else if(se.contains("tag was lost")){
alertMsg = "Tag was lost. Please try again!";
}
else if(se.contains("invalidated by user")){
alertMsg = "";
}
setState(() {
_alertMessage = alertMsg;
});
}
finally {
if(_alertMessage.isNotEmpty){
await _nfc.disconnect(iosErrorMessage: _alertMessage);
}
else {
await _nfc.disconnect(iosAlertMessage: formatProgressMsg("Finished", 100));
}
setState(() {
_isReading = false;
});
}
}
@override
Widget build(BuildContext context) {
return PlatformProvider(
builder: (BuildContext context) => _buildPage(context)
);
}
bool _disabledInput() {
return _isReading || !_isNfcAvailable;
}
Widget _makeMrtdDataWidget({required String header, required String collapsedText, required dataText}) {
return ExpandablePanel(
theme: const ExpandableThemeData(
headerAlignment: ExpandablePanelHeaderAlignment.center,
tapBodyToCollapse: true,
hasIcon: true,
iconColor: Colors.red,
),
header: Text(header),
collapsed: Text(collapsedText, softWrap: true, maxLines: 2, overflow: TextOverflow.ellipsis),
expanded: Container(
padding: const EdgeInsets.all(18),
color: Color.fromARGB(255, 239, 239, 239),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
PlatformTextButton(
child: Text('Copy'),
onPressed: () => Clipboard.setData(ClipboardData(text: dataText)),
padding: const EdgeInsets.all(8),
),
SelectableText(dataText, textAlign: TextAlign.left)
])
));
}
List<Widget> _mrtdDataWidgets() {
List<Widget> list = [];
if (_mrtdData == null) return list;
if (_mrtdData!.cardAccess != null) {
list.add(_makeMrtdDataWidget(header: 'EF.CardAccess', collapsedText: '', dataText: _mrtdData!.cardAccess!.toBytes().hex()));
}
if (_mrtdData!.cardSecurity != null) {
list.add(_makeMrtdDataWidget(header: 'EF.CardSecurity', collapsedText: '', dataText: _mrtdData!.cardSecurity!.toBytes().hex()));
}
if (_mrtdData!.sod != null) {
list.add(_makeMrtdDataWidget(header: 'EF.SOD', collapsedText: '', dataText: _mrtdData!.sod!.toBytes().hex()));
}
if (_mrtdData!.com != null) {
list.add(_makeMrtdDataWidget(header: 'EF.COM', collapsedText: '', dataText: formatEfCom(_mrtdData!.com!)));
}
if (_mrtdData!.dg1 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG1', collapsedText: '', dataText: formatMRZ(_mrtdData!.dg1!.mrz)));
}
if (_mrtdData!.dg2 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG2', collapsedText: '', dataText: _mrtdData!.dg2!.toBytes().hex()));
}
if (_mrtdData!.dg3 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG3', collapsedText: '', dataText: _mrtdData!.dg3!.toBytes().hex()));
}
if (_mrtdData!.dg4 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG4', collapsedText: '', dataText: _mrtdData!.dg4!.toBytes().hex()));
}
if (_mrtdData!.dg5 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG5', collapsedText: '', dataText: _mrtdData!.dg5!.toBytes().hex()));
}
if (_mrtdData!.dg6 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG6', collapsedText: '', dataText: _mrtdData!.dg6!.toBytes().hex()));
}
if (_mrtdData!.dg7 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG7', collapsedText: '', dataText: _mrtdData!.dg7!.toBytes().hex()));
}
if (_mrtdData!.dg8 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG8', collapsedText: '', dataText: _mrtdData!.dg8!.toBytes().hex()));
}
if (_mrtdData!.dg9 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG9', collapsedText: '', dataText: _mrtdData!.dg9!.toBytes().hex()));
}
if (_mrtdData!.dg10 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG10', collapsedText: '', dataText: _mrtdData!.dg10!.toBytes().hex()));
}
if (_mrtdData!.dg11 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG11', collapsedText: '', dataText: _mrtdData!.dg11!.toBytes().hex()));
}
if (_mrtdData!.dg12 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG12', collapsedText: '', dataText: _mrtdData!.dg12!.toBytes().hex()));
}
if (_mrtdData!.dg13 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG13', collapsedText: '', dataText: _mrtdData!.dg13!.toBytes().hex()));
}
if (_mrtdData!.dg14 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG14', collapsedText: '', dataText: _mrtdData!.dg14!.toBytes().hex()));
}
if (_mrtdData!.dg15 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG15', collapsedText: '', dataText: _mrtdData!.dg15!.toBytes().hex()));
}
if (_mrtdData!.aaSig != null) {
list.add(_makeMrtdDataWidget(header: 'Active Authentication signature', collapsedText: '', dataText: _mrtdData!.aaSig!.hex()));
}
if (_mrtdData!.dg16 != null) {
list.add(_makeMrtdDataWidget(header: 'EF.DG16', collapsedText: '', dataText: _mrtdData!.dg16!.toBytes().hex()));
}
return list;
}
PlatformScaffold _buildPage(BuildContext context) => PlatformScaffold(
appBar: PlatformAppBar(
title: Text('MRTD Example App')
),
iosContentPadding: false,
iosContentBottomPadding: false,
body: Material(
child: SafeArea(
child: Padding(
padding: EdgeInsets.all(8.0),
child: SingleChildScrollView(
controller: _scrollController,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SizedBox(height: 20),
Row(children: <Widget>[
Text('NFC available:',
style: TextStyle(fontSize: 18.0 , fontWeight: FontWeight.bold)
),
SizedBox(width: 4),
Text(_isNfcAvailable ? "Yes" : "No",
style: TextStyle(fontSize: 18.0)
)
]),
SizedBox(height: 40),
_buildForm(context),
SizedBox(height: 20),
PlatformElevatedButton( // btn Read MRTD
onPressed: _disabledInput() || !_mrzData.currentState!.validate() ? null : _readMRTD,
child: PlatformText(_isReading ? 'Reading ...' : 'Read Passport'),
),
SizedBox(height: 4),
Text(_alertMessage,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 15.0 , fontWeight: FontWeight.bold)
),
SizedBox(height: 15),
Padding(
padding: EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(_mrtdData != null ? "Passport Data:" : "",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 15.0 , fontWeight: FontWeight.bold)
),
Padding(
padding: EdgeInsets.only(left: 16.0, top: 8.0, bottom: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _mrtdDataWidgets()
)
)
]
),
),
]
)
)
)
)
)
);
Padding _buildForm(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(vertical: 8.0, horizontal: 30.0),
child: Form(
key: _mrzData,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
TextFormField(
enabled: !_disabledInput(),
controller: _docNumber,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Passport number',
fillColor: Colors.white
),
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp(r'[A-Z0-9]+')),
LengthLimitingTextInputFormatter(14)
],
textInputAction: TextInputAction.done,
textCapitalization: TextCapitalization.characters,
autofocus: true,
validator: (value) {
if (value?.isEmpty ?? false) {
return 'Please enter passport number';
}
return null;
},
),
SizedBox(height: 12),
TextFormField(
enabled: !_disabledInput(),
controller: _dob,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Date of Birth',
fillColor: Colors.white
),
autofocus: false,
validator: (value) {
if (value?.isEmpty ?? false) {
return 'Please select Date of Birth';
}
return null;
},
onTap: () async {
FocusScope.of(context).requestFocus(FocusNode());
// Can pick date which dates 15 years back or more
final now = DateTime.now();
final firstDate = DateTime(now.year - 90, now.month, now.day);
final lastDate = DateTime(now.year - 15, now.month, now.day);
final initDate = _getDOBDate();
final date = await _pickDate(context,
firstDate, initDate ?? lastDate, lastDate
);
FocusScope.of(context).requestFocus(FocusNode());
if(date != null) {
_dob.text = date;
}
}
),
SizedBox(height: 12),
TextFormField(
enabled: !_disabledInput(),
controller: _doe,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Date of Expiry',
fillColor: Colors.white
),
autofocus: false,
validator: (value) {
if (value?.isEmpty ?? false) {
return 'Please select Date of Expiry';
}
return null;
},
onTap: () async {
FocusScope.of(context).requestFocus(FocusNode());
// Can pick date from tomorrow and up to 10 years
final now = DateTime.now();
final firstDate = DateTime(now.year, now.month, now.day + 1);
final lastDate = DateTime(now.year + 10, now.month + 6, now.day);
final initDate = _getDOEDate();
final date = await _pickDate(context, firstDate,
initDate ?? firstDate, lastDate
);
FocusScope.of(context).requestFocus(FocusNode());
if(date != null) {
_doe.text = date;
}
}
)
],
),
)
);
}
}