fabienrousseau / flutter_pcsc

A Flutter plugin for using PCSC smartcard readers on Windows/macOS/Linux.
14 stars 11 forks source link

waitForCardPresent throws error #6

Open nhim175 opened 1 year ago

nhim175 commented 1 year ago

I found some issue with waitForCardPresent on Mac so I open this ticket.

Issue

waitForCardPresent method throws an error: type 'Null' is not a subtype of type 'int'

Steps to reproduce

  1. Connect to a card reader
  2. Execute the below code (bind to a click handler or something). Most of the code is copied from the example, except for the use of waitForCardPresent

    readCard() async {
    int ctx = await Pcsc.establishContext(PcscSCope.user);
    print('Context: $ctx');
    List<String> readers = await Pcsc.listReaders(ctx);
    
    if (readers.isEmpty) {
      print('Could not detect any reader');
    } else {
      String reader = readers[0];
      print('Using reader: $reader');
      await Pcsc.waitForCardPresent(ctx, reader); // <-------- This line throw error
      CardStruct card = await Pcsc.cardConnect(
          ctx, reader, PcscShare.shared, PcscProtocol.any);
      var response = await Pcsc.transmit(card, [0xFF, 0xCA, 0x00, 0x00, 0x00]);
      print('Response: ${hexDump(response)}');
    
      await Pcsc.cardDisconnect(card.hCard, PcscDisposition.resetCard);
    }
    await Pcsc.releaseContext(ctx);
    }

What's the expected result?

What's the actual result?

Additional details / screenshot

Error message:

flutter: Context: 2
flutter: Using reader: SONY FeliCa RC-S300/P
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'int'
#0      PCSCBinding.waitForCardPresent (package:flutter_pcsc_macos/src/pcsc_bindings.dart:149:9)
<asynchronous suspension>
#1      BootScreen.readCard (package:uniform_client_app_flutter/screens/boot.dart:37:7)
<asynchronous suspension>
milkyway044 commented 1 year ago

the same: ACS ACR1281 1S Dual Reader macOS 12.6.2 flutter 3.7.5

Снимок экрана 2023-02-27 в 16 25 58
milkyway044 commented 1 year ago

missing one line on two platforms: macos and windows after adding everything works as expected!