Compare commits
No commits in common. '4285d29d187bf76c1a3e3aa1fc7f6bdbf53e5452' and '1c7df8d8c1f764c90fa9cf7f0eae8a089763c0af' have entirely different histories.
4285d29d18
...
1c7df8d8c1
@ -1,249 +1,247 @@
|
|||||||
//TODO delete unused file
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
// import 'dart:async';
|
|
||||||
// import 'dart:io';
|
import 'package:flutter/material.dart';
|
||||||
//
|
import 'package:nfc_manager/nfc_manager.dart';
|
||||||
// import 'package:flutter/material.dart';
|
|
||||||
// // import 'package:nfc_manager/nfc_manager.dart';
|
void showNfcReader(BuildContext context, {required Function(String? nfcId) onNcfScan}) {
|
||||||
//
|
showModalBottomSheet(
|
||||||
// void showNfcReader(BuildContext context, {required Function(String? nfcId) onNcfScan}) {
|
context: context,
|
||||||
// showModalBottomSheet(
|
enableDrag: false,
|
||||||
// context: context,
|
isDismissible: false,
|
||||||
// enableDrag: false,
|
shape: RoundedRectangleBorder(
|
||||||
// isDismissible: false,
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)),
|
||||||
// shape: const RoundedRectangleBorder(
|
),
|
||||||
// borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)),
|
backgroundColor: Colors.white,
|
||||||
// ),
|
builder: (context) {
|
||||||
// backgroundColor: Colors.white,
|
return NfcLayout(
|
||||||
// builder: (context) {
|
onNcfScan: onNcfScan,
|
||||||
// return NfcLayout(
|
);
|
||||||
// onNcfScan: onNcfScan,
|
},
|
||||||
// );
|
);
|
||||||
// },
|
}
|
||||||
// );
|
|
||||||
// }
|
class NfcLayout extends StatefulWidget {
|
||||||
//
|
final Function(String? nfcId) onNcfScan;
|
||||||
// class NfcLayout extends StatefulWidget {
|
|
||||||
// final Function(String? nfcId) onNcfScan;
|
const NfcLayout({super.key, required this.onNcfScan});
|
||||||
//
|
|
||||||
// const NfcLayout({super.key, required this.onNcfScan});
|
@override
|
||||||
//
|
_NfcLayoutState createState() => _NfcLayoutState();
|
||||||
// @override
|
}
|
||||||
// _NfcLayoutState createState() => _NfcLayoutState();
|
|
||||||
// }
|
class _NfcLayoutState extends State<NfcLayout> {
|
||||||
//
|
bool _reading = false;
|
||||||
// class _NfcLayoutState extends State<NfcLayout> {
|
Widget? mainWidget;
|
||||||
// bool _reading = false;
|
String? nfcId;
|
||||||
// Widget? mainWidget;
|
|
||||||
// String? nfcId;
|
@override
|
||||||
//
|
void initState() {
|
||||||
// @override
|
super.initState();
|
||||||
// void initState() {
|
|
||||||
// super.initState();
|
NfcManager.instance.startSession(
|
||||||
//
|
onDiscovered: (NfcTag tag) async {
|
||||||
// NfcManager.instance.startSession(
|
String? identifier;
|
||||||
// onDiscovered: (NfcTag tag) async {
|
|
||||||
// String? identifier;
|
// Access tag identifier from the tag data
|
||||||
//
|
// In nfc_manager 4.1.1, access data via dynamic cast to bypass protected member
|
||||||
// // Access tag identifier from the tag data
|
try {
|
||||||
// // In nfc_manager 4.1.1, access data via dynamic cast to bypass protected member
|
final dynamic tagDynamic = tag;
|
||||||
// try {
|
final Map<String, dynamic> tagData = Map<String, dynamic>.from(tagDynamic.data as Map);
|
||||||
// final dynamic tagDynamic = tag;
|
|
||||||
// final Map<String, dynamic> tagData = Map<String, dynamic>.from(tagDynamic.data as Map);
|
if (Platform.isAndroid) {
|
||||||
//
|
// For Android, try NfcA technology first
|
||||||
// if (Platform.isAndroid) {
|
if (tagData.containsKey('nfca')) {
|
||||||
// // For Android, try NfcA technology first
|
final nfcaData = tagData['nfca'] as Map<dynamic, dynamic>;
|
||||||
// if (tagData.containsKey('nfca')) {
|
if (nfcaData.containsKey('identifier')) {
|
||||||
// final nfcaData = tagData['nfca'] as Map<dynamic, dynamic>;
|
final List<int> idBytes = List<int>.from(nfcaData['identifier'] as List);
|
||||||
// if (nfcaData.containsKey('identifier')) {
|
identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
||||||
// final List<int> idBytes = List<int>.from(nfcaData['identifier'] as List);
|
}
|
||||||
// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
}
|
||||||
// }
|
// Fallback to other technologies if NfcA is not available
|
||||||
// }
|
if (identifier == null && tagData.containsKey('nfcb')) {
|
||||||
// // Fallback to other technologies if NfcA is not available
|
final nfcbData = tagData['nfcb'] as Map<dynamic, dynamic>;
|
||||||
// if (identifier == null && tagData.containsKey('nfcb')) {
|
if (nfcbData.containsKey('identifier')) {
|
||||||
// final nfcbData = tagData['nfcb'] as Map<dynamic, dynamic>;
|
final List<int> idBytes = List<int>.from(nfcbData['identifier'] as List);
|
||||||
// if (nfcbData.containsKey('identifier')) {
|
identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
||||||
// final List<int> idBytes = List<int>.from(nfcbData['identifier'] as List);
|
}
|
||||||
// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
}
|
||||||
// }
|
} else {
|
||||||
// }
|
// For iOS, try MiFare technology
|
||||||
// } else {
|
if (tagData.containsKey('mifare')) {
|
||||||
// // For iOS, try MiFare technology
|
final mifareData = tagData['mifare'] as Map<dynamic, dynamic>;
|
||||||
// if (tagData.containsKey('mifare')) {
|
if (mifareData.containsKey('identifier')) {
|
||||||
// final mifareData = tagData['mifare'] as Map<dynamic, dynamic>;
|
final List<int> idBytes = List<int>.from(mifareData['identifier'] as List);
|
||||||
// if (mifareData.containsKey('identifier')) {
|
identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
||||||
// final List<int> idBytes = List<int>.from(mifareData['identifier'] as List);
|
}
|
||||||
// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
}
|
||||||
// }
|
// Fallback to iso15693 for iOS
|
||||||
// }
|
if (identifier == null && tagData.containsKey('iso15693')) {
|
||||||
// // Fallback to iso15693 for iOS
|
final iso15693Data = tagData['iso15693'] as Map<dynamic, dynamic>;
|
||||||
// if (identifier == null && tagData.containsKey('iso15693')) {
|
if (iso15693Data.containsKey('identifier')) {
|
||||||
// final iso15693Data = tagData['iso15693'] as Map<dynamic, dynamic>;
|
final List<int> idBytes = List<int>.from(iso15693Data['identifier'] as List);
|
||||||
// if (iso15693Data.containsKey('identifier')) {
|
identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
||||||
// final List<int> idBytes = List<int>.from(iso15693Data['identifier'] as List);
|
}
|
||||||
// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
// }
|
// Universal fallback: try Ndef if available
|
||||||
//
|
if (identifier == null && tagData.containsKey('ndef')) {
|
||||||
// // Universal fallback: try Ndef if available
|
final ndefData = tagData['ndef'] as Map<dynamic, dynamic>;
|
||||||
// if (identifier == null && tagData.containsKey('ndef')) {
|
if (ndefData.containsKey('identifier')) {
|
||||||
// final ndefData = tagData['ndef'] as Map<dynamic, dynamic>;
|
final List<int> idBytes = List<int>.from(ndefData['identifier'] as List);
|
||||||
// if (ndefData.containsKey('identifier')) {
|
identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
||||||
// final List<int> idBytes = List<int>.from(ndefData['identifier'] as List);
|
}
|
||||||
// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
|
}
|
||||||
// }
|
} catch (e) {
|
||||||
// }
|
print('Error reading NFC tag: $e');
|
||||||
// } catch (e) {
|
}
|
||||||
// print('Error reading NFC tag: $e');
|
|
||||||
// }
|
nfcId = identifier;
|
||||||
//
|
|
||||||
// nfcId = identifier;
|
setState(() {
|
||||||
//
|
_reading = true;
|
||||||
// setState(() {
|
mainWidget = doneNfc();
|
||||||
// _reading = true;
|
});
|
||||||
// mainWidget = doneNfc();
|
|
||||||
// });
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
//
|
NfcManager.instance.stopSession();
|
||||||
// Future.delayed(const Duration(seconds: 1), () {
|
Navigator.pop(context);
|
||||||
// NfcManager.instance.stopSession();
|
widget.onNcfScan(nfcId);
|
||||||
// Navigator.pop(context);
|
});
|
||||||
// widget.onNcfScan(nfcId);
|
},
|
||||||
// });
|
pollingOptions: {NfcPollingOption.iso14443},
|
||||||
// },
|
).catchError((err) {
|
||||||
// pollingOptions: {NfcPollingOption.iso14443},
|
print(err);
|
||||||
// ).catchError((err) {
|
});
|
||||||
// print(err);
|
}
|
||||||
// });
|
|
||||||
// }
|
@override
|
||||||
//
|
Widget build(BuildContext context) {
|
||||||
// @override
|
(mainWidget == null && !_reading) ? mainWidget = scanNfc() : mainWidget = doneNfc();
|
||||||
// Widget build(BuildContext context) {
|
return AnimatedSwitcher(duration: Duration(milliseconds: 500), child: mainWidget);
|
||||||
// (mainWidget == null && !_reading) ? mainWidget = scanNfc() : mainWidget = doneNfc();
|
}
|
||||||
// return AnimatedSwitcher(duration: Duration(milliseconds: 500), child: mainWidget);
|
|
||||||
// }
|
Widget scanNfc() {
|
||||||
//
|
return Container(
|
||||||
// Widget scanNfc() {
|
key: ValueKey(1),
|
||||||
// return Container(
|
child: Column(
|
||||||
// key: ValueKey(1),
|
mainAxisSize: MainAxisSize.min,
|
||||||
// child: Column(
|
children: <Widget>[
|
||||||
// mainAxisSize: MainAxisSize.min,
|
SizedBox(
|
||||||
// children: <Widget>[
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
Text(
|
||||||
// ),
|
"Ready To Scan",
|
||||||
// Text(
|
style: TextStyle(
|
||||||
// "Ready To Scan",
|
fontWeight: FontWeight.bold,
|
||||||
// style: TextStyle(
|
fontSize: 24,
|
||||||
// fontWeight: FontWeight.bold,
|
),
|
||||||
// fontSize: 24,
|
),
|
||||||
// ),
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
Image.asset(
|
||||||
// ),
|
"assets/images/nfc_dummy.png",
|
||||||
// Image.asset(
|
height: MediaQuery.of(context).size.width / 3,
|
||||||
// "assets/images/nfc_dummy.png",
|
width: double.infinity,
|
||||||
// height: MediaQuery.of(context).size.width / 3,
|
),
|
||||||
// width: double.infinity,
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
Text(
|
||||||
// ),
|
"Approach an NFC Tag",
|
||||||
// Text(
|
style: TextStyle(
|
||||||
// "Approach an NFC Tag",
|
fontSize: 18,
|
||||||
// style: TextStyle(
|
),
|
||||||
// fontSize: 18,
|
),
|
||||||
// ),
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
ButtonTheme(
|
||||||
// ),
|
minWidth: MediaQuery.of(context).size.width / 1.2,
|
||||||
// ButtonTheme(
|
height: 45.0,
|
||||||
// minWidth: MediaQuery.of(context).size.width / 1.2,
|
buttonColor: Colors.grey[300],
|
||||||
// height: 45.0,
|
shape: RoundedRectangleBorder(
|
||||||
// buttonColor: Colors.grey[300],
|
borderRadius: BorderRadius.circular(6),
|
||||||
// shape: RoundedRectangleBorder(
|
),
|
||||||
// borderRadius: BorderRadius.circular(6),
|
child: TextButton(
|
||||||
// ),
|
onPressed: () {
|
||||||
// child: TextButton(
|
NfcManager.instance.stopSession();
|
||||||
// onPressed: () {
|
Navigator.pop(context);
|
||||||
// NfcManager.instance.stopSession();
|
},
|
||||||
// Navigator.pop(context);
|
// elevation: 0,
|
||||||
// },
|
child: Text("CANCEL"),
|
||||||
// // elevation: 0,
|
),
|
||||||
// child: Text("CANCEL"),
|
),
|
||||||
// ),
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
],
|
||||||
// ),
|
),
|
||||||
// ],
|
);
|
||||||
// ),
|
}
|
||||||
// );
|
|
||||||
// }
|
Widget doneNfc() {
|
||||||
//
|
return Container(
|
||||||
// Widget doneNfc() {
|
key: ValueKey(2),
|
||||||
// return Container(
|
child: Column(
|
||||||
// key: ValueKey(2),
|
mainAxisSize: MainAxisSize.min,
|
||||||
// child: Column(
|
children: <Widget>[
|
||||||
// mainAxisSize: MainAxisSize.min,
|
SizedBox(
|
||||||
// children: <Widget>[
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
Text(
|
||||||
// ),
|
"Successfully Scanned",
|
||||||
// Text(
|
style: TextStyle(
|
||||||
// "Successfully Scanned",
|
fontWeight: FontWeight.bold,
|
||||||
// style: TextStyle(
|
fontSize: 24,
|
||||||
// fontWeight: FontWeight.bold,
|
),
|
||||||
// fontSize: 24,
|
),
|
||||||
// ),
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
Image.asset(
|
||||||
// ),
|
// "assets/icons/nfc/ic_done.png",
|
||||||
// Image.asset(
|
"assets/images/done_dummy.jpeg",
|
||||||
// // "assets/icons/nfc/ic_done.png",
|
height: MediaQuery.of(context).size.width / 3,
|
||||||
// "assets/images/done_dummy.jpeg",
|
width: double.infinity,
|
||||||
// height: MediaQuery.of(context).size.width / 3,
|
),
|
||||||
// width: double.infinity,
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
Text(
|
||||||
// ),
|
"Approach an NFC Tag",
|
||||||
// Text(
|
style: TextStyle(
|
||||||
// "Approach an NFC Tag",
|
fontSize: 18,
|
||||||
// style: TextStyle(
|
),
|
||||||
// fontSize: 18,
|
),
|
||||||
// ),
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
ButtonTheme(
|
||||||
// ),
|
minWidth: MediaQuery.of(context).size.width / 1.2,
|
||||||
// ButtonTheme(
|
height: 45.0,
|
||||||
// minWidth: MediaQuery.of(context).size.width / 1.2,
|
buttonColor: Colors.grey[300],
|
||||||
// height: 45.0,
|
shape: RoundedRectangleBorder(
|
||||||
// buttonColor: Colors.grey[300],
|
borderRadius: BorderRadius.circular(6),
|
||||||
// shape: RoundedRectangleBorder(
|
),
|
||||||
// borderRadius: BorderRadius.circular(6),
|
child: TextButton(
|
||||||
// ),
|
// onPressed: () {
|
||||||
// child: TextButton(
|
// _stream?.cancel();
|
||||||
// // onPressed: () {
|
// widget.onNcfScan(nfcId);
|
||||||
// // _stream?.cancel();
|
// Navigator.pop(context);
|
||||||
// // widget.onNcfScan(nfcId);
|
// },
|
||||||
// // Navigator.pop(context);
|
onPressed: null,
|
||||||
// // },
|
// elevation: 0,
|
||||||
// onPressed: null,
|
child: Text("DONE"),
|
||||||
// // elevation: 0,
|
),
|
||||||
// child: Text("DONE"),
|
),
|
||||||
// ),
|
SizedBox(
|
||||||
// ),
|
height: 30,
|
||||||
// SizedBox(
|
),
|
||||||
// height: 30,
|
],
|
||||||
// ),
|
),
|
||||||
// ],
|
);
|
||||||
// ),
|
}
|
||||||
// );
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|||||||
Loading…
Reference in New Issue