flutter-nfc-manager icon indicating copy to clipboard operation
flutter-nfc-manager copied to clipboard

v4.0.0 release

Open okadan opened this issue 2 years ago • 9 comments

  • [] Replace internal implementation with pigeon.
  • [] Covers all APIs for Android and iOS.
  • [] Move tag-specific APIs to external packages.
  • [] Add docs.
  • [] Test with a real world app.

okadan avatar Mar 05 '23 01:03 okadan

Hi @okadan , Any progress getting 4.0.0 released? I was playing with it, but get an error message when running on an Android (Samsung A2): E/flutter ( 9784): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument: Instance of 'PigeonReaderFlag' E/flutter ( 9784): #0 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:466:7) E/flutter ( 9784): #1 _PigeonHostApiCodec.writeValue (package:nfc_manager/src/nfc_manager_android/pigeon.g.dart:608:13) E/flutter ( 9784): #2 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:456:9) E/flutter ( 9784): #3 _PigeonHostApiCodec.writeValue (package:nfc_manager/src/nfc_manager_android/pigeon.g.dart:608:13) E/flutter ( 9784): #4 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:456:9) E/flutter ( 9784): #5 _PigeonHostApiCodec.writeValue (package:nfc_manager/src/nfc_manager_android/pigeon.g.dart:608:13) E/flutter ( 9784): #6 StandardMessageCodec.encodeMessage (package:flutter/src/services/message_codecs.dart:333:5) E/flutter ( 9784): #7 BasicMessageChannel.send (package:flutter/src/services/platform_channel.dart:197:71) E/flutter ( 9784): #8 PigeonHostApi.adapterEnableReaderMode (package:nfc_manager/src/nfc_manager_android/pigeon.g.dart:723:23) E/flutter ( 9784): #9 NfcManagerAndroid.enableReaderMode (package:nfc_manager/src/nfc_manager_android/nfc_manager.dart:40:20) E/flutter ( 9784): #10 NfcManagerAndroidPlatform.startSession (package:nfc_manager/src/nfc_manager_android/nfc_manager_platform.dart:18:39) E/flutter ( 9784): #11 NfcManager.startSession (package:nfc_manager/src/nfc_manager/nfc_manager.dart:33:40)

I used this dependency: nfc_manager: git: url: https://github.com/okadan/flutter-nfc-manager.git ref: v4.0.0

Any ideas?

jakusb avatar Apr 15 '23 12:04 jakusb

When running on my iPhoneX I get a different message: [VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument: Instance of 'PigeonPollingOption' #0 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:466:7) #1 _PigeonHostApiCodec.writeValue (package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart:814:13) #2 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:456:9) #3 _PigeonHostApiCodec.writeValue (package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart:814:13) #4 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:456:9) #5 _PigeonHostApiCodec.writeValue (package:nfc_manager/src/nfc_manager_ios/pigeon.g.dart:814:13) #6 StandardMessageCodec.encodeMessage (package:flutter/src/services/message_codecs.dart:333:5) #7 BasicMessageChannel.send (package:flutter/src/services/platform_channel.dart:197:71)

jakusb avatar Apr 15 '23 13:04 jakusb

Hey, I was checking out this branch and I'm very much looking forward to this release because of problems I'm having with my particular use case seemingly causing tags to be disposed before I'm done with them. Do you perhaps have a timeline of when you expect the new version to be released?

PeteClubSeven avatar Apr 21 '23 17:04 PeteClubSeven

Hey, I was checking out this branch and I'm very much looking forward to this release because of problems I'm having with my particular use case seemingly causing tags to be disposed before I'm done with them. Do you perhaps have a timeline of when you expect the new version to be released?

I had similar issues, here a summary of what I did:

  • Android requires continues scanning session, simply to prevent it from triggering native response from outside of app. I simply stopSession after every read and immediately startSession again

  • I use a Cubit to emit event whenever a tag is read

  • iOS does not seem to support continuous scanning and requires explicit startSession, as it will timeout otherwise.

  • I added 2 functions to assist in preventing timing issues:

      String? nextAlertMessageIOS;
      String? nextErrorMessageIOS;
      Future<void> Function(NfcTag nfcTag, Ndef ndef)? onNextRead;
      Future<void> Function()? afterSessionStopped;
    
  • I used async/await everywhere to enforce single threaded processing.
    await NfcManager.instance.startSession(alertMessage: alertMessageIOS,onDiscovered: (NfcTag nfcTag) async { loggy.info('startSession tag[$nfcTag] handle[${nfcTag.handle}]'); Ndef? ndef = Ndef.from(nfcTag); loggy.debug('PRE onReadTag'); NfcState currentState = state; if (currentState is NfcStateLoaded) { emit(currentState.from(nfcTag: nfcTag, ndef: ndef)); } await onReadTag(nfcTag, ndef, count); loggy.debug('POST onReadTag'); Future Function(NfcTag nfcTag, Ndef ndef)? currentOnNextRead = onNextRead; if (currentOnNextRead != null && ndef != null) { await currentOnNextRead(nfcTag, ndef); onNextRead = null; } await stopSession(alertMessageIOS: nextAlertMessageIOS, errorMessageIOS: nextErrorMessageIOS); nextAlertMessageIOS = null; nextErrorMessageIOS = null; Future Function()? currentAfterSessionStopped = afterSessionStopped; if (currentAfterSessionStopped != null) { await currentAfterSessionStopped(); } loggy.debug('stopSession done'); if (continuous) { if (!kIsWeb && Platform.isIOS) { await Future.delayed(const Duration(seconds: 4)).then((value) {}); } loggy.debug('stopSession continue [$count}]'); count++; await readTag(continuous: continuous, count: count, alertMessageIOS: alertMessageIOS, onReadTag: onReadTag); } }); loggy.debug('DONE readTag');

jakusb avatar Apr 21 '23 21:04 jakusb

I'm also looking forward to 4.0.0. In particular, I wonder if "Covers all APIs for Android and iOS." includes transceiving commands via NfcA.from(...).transceive(...) on iOS. Does anyone know?

sant0s avatar Apr 24 '23 09:04 sant0s

Hi, @okadan Any update on the new release?

FTKhanFT avatar May 20 '23 14:05 FTKhanFT

@okadan is there anything you need help with get this released?

martijn00 avatar Oct 11 '23 20:10 martijn00

@martijn00 I`m planning to try implementing the Android HCE, but I would appreciate it if you can help me.

okadan avatar Oct 14 '23 02:10 okadan