semlette / nfc_in_flutter

Cross-platform flutter plugin for reading and writing NFC tags. Not maintained anymore - not looking for new maintainer, fork instead.
MIT License
119 stars 119 forks source link

PlatformException on write #98

Open DasElias opened 2 years ago

DasElias commented 2 years ago

When I start my app and click a button (which executes the following code), I get a PlatformException(IOError, null, null, null) in the line, where the tag is written. This issue seems to have nothing to do with the tag itself, because when I try to write that particular string in a NFC-write-app, everything works correctly.

  Future<void> nfc() async {
    print("start reading");
    Stream<NDEFMessage> stream = NFC.readNDEF();
    NDEFMessage tag = await stream.first;
    // do something with tag content
    print("read finished");

    NDEFMessage msg = NDEFMessage.withRecords([
      NDEFRecord.text("docmanagement:5a900ee9-003b-4777-9295-a656d8c8810a:aa351a8f-227a-4658-a672-48a319305740"),
    ]);
    await tag.tag.write(msg);
    print("write finished");
  }
mislavlukach commented 2 years ago

Same thing here. It seems to be working but then it just stops. You can't write multiple times in a row. To be more specific, it works 9/10 times. But this one time I'm constantly getting PlatformException with this error message "write to tag error: Tag is not ndef" which makes no sense since I'm quite sure it's NDEF

ElegantCrab commented 2 years ago

This same problem is affecting me. It worked completely fine before then suddenly this starts happening.

Some insight into the problem: To me, it only happens with empty NFCs, otherwise it works fine.

Update: Running some tests, it only fails when the NFC is not formatted to Ndef on certain phones. On a phone with Android 9 works perfectly but on a phone BISON with Android 11, it seems to fail.