我如何使用 Flutter 读取 NFC 信用卡详细信息,例如卡号、到期日期和 cvv。我尝试过使用 flutter nfc kit 和 Nfc manager 等软件包,但它似乎没有达到我想要的效果。
Future<void> readCardData() async {
try {
// Check if NFC is supported on the device
bool isAvailable = await NfcManager.instance.isAvailable();
if (!isAvailable) {
throw Exception('NFC is not available on this device');
}
// Start the NFC session
await NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
Ndef? ndef = Ndef.from(tag);
if (ndef == null) {
throw Exception('Tag is not compatible with NDEF');
}
// Read NDEF message from tag
NdefMessage message = await ndef.read();
if (message == null) {
Get.snackbar('Error', 'Tag is empty',
snackPosition: SnackPosition.BOTTOM);
throw Exception('Tag is empty');
} else {
// Parse the message and extract card data
NdefRecord record = message.records.first;
String payload = String.fromCharCodes(record.payload);
List<String> fields = payload.split('|');
if (fields.length != 4) {
throw Exception('Invalid card data format');
}
cardNumber = fields[0];
cardHolderName = fields[1];
expiryDate = fields[2];
cvv = fields[3];
// Update the UI with the card data
update();
Get.toNamed(
'/debit-sms',
arguments: receiveController.text,
);
}
});
} catch (e) {
print(e);
}
}
我发帖作为回应,因为我没有足够的声誉来发表评论。
我对 Flutter 没有太多经验,但在 ReactNative 中帮助过类似的事情,你可以在here找到该存储库。
观察:通过 NFC 无法从卡中读取 CVV。
步骤如下:
所有这些步骤都是在我共享的存储库上的 ReactNative 中完成的,从这里
开始抱歉,您找到了颤振的解决方案吗?请我现在需要它。谢谢