fabienrousseau/flutter_pcsc

waitForCardPresent throws error

Opened this issue · 2 comments

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?

  • No errors should be thrown

What's the actual result?

  • Error is thrown when the function runs

Additional details / screenshot

  • OS: Mac Ventura
  • Device: SONY FeliCa RC-S300/P

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>

the same:
ACS ACR1281 1S Dual Reader
macOS 12.6.2
flutter 3.7.5
Снимок экрана 2023-02-27 в 16 25 58

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