nfcim / flutter_nfc_kit

Flutter plugin to provide NFC functionality on Android and iOS, including reading metadata, read & write NDEF records, and transceive layer 3 & 4 data with NFC tags / cards
https://pub.dev/packages/flutter_nfc_kit
MIT License
200 stars 121 forks source link

读取扇区数据失败 #148

Closed LIUbacon closed 6 months ago

LIUbacon commented 9 months ago

//读取

Future readBlock() async { if (tag.type == NFCTagType.mifare_classic) { try{

     await FlutterNfcKit.authenticateSector(0, keyA: "FFFFFFFFFFFF", keyB: "FFFFFFFFFFFF");
     var data = await FlutterNfcKit.readSector(0); // read one sector, or
     var data2 = await FlutterNfcKit.readBlock(0); // read one block
     print(data);
     print(data2);
   } catch(e){
     print('读取失败$e');
   }
 }

} 提示:读取失败'package:flutter_nfc_kit/flutter_nfc_kit.dart': Failed assertion: line 453 pos 12: 'T is String || T is Uint8List': is not true.

'package:flutter_nfc_kit/flutter_nfc_kit.dart'部分代码 Uint8List 提示错误 手动添加import 'dart:typed_data'; /// Transceive data with the card / tag in the format of APDU (iso7816) or raw commands (other technologies). /// The [capdu] can be either of type Uint8List or hex string. /// Return value will be in the same type of [capdu]. /// /// There must be a valid session when invoking. /// /// On Android, [timeout] parameter will set transceive execution timeout that is persistent during a active session. /// Also, Ndef TagTechnology will be closed if active. /// On iOS, this parameter is ignored and is decided by the OS. /// On Web, [timeout] is currently not /// Timeout is reset to default value when [finish] is called, and could be changed by multiple calls to [transceive]. static Future transceive(T capdu, {Duration? timeout}) async { assert(capdu is String || capdu is Uint8List); return await _channel.invokeMethod('transceive', { 'data': capdu, 'timeout': timeout?.inMilliseconds ?? TRANSCEIVE_TIMEOUT }); }

LIUbacon commented 9 months ago

Flutter版本2.5.0,dart2.14.0,使用的flutter_nfc_kit: ^3.4.2

//读取扇区数据 Future readBlock() async { if (tag.type == NFCTagType.mifare_classic) { try{ Uint8List keyA = Uint8List.fromList([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]); Uint8List keyB = Uint8List.fromList([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);

     await FlutterNfcKit.authenticateSector(0,keyA: keyA,keyB: keyB);
     var data = await FlutterNfcKit.readSector(0); // read one sector, or
     var data2 = await FlutterNfcKit.readBlock(0); // read one block
     print(data);
     print(data2);
   } catch(e){
     print('读取失败$e');
   }
 }

} 都是提示读取失败'package:flutter_nfc_kit/flutter_nfc_kit.dart': Failed assertion: line 453 pos 12: 'T is String || T is Uint8List': is not true.