NFC read/write with flutter

12,992

Solution 1

I think what you're looking to do is definitely possible, but as you mentioned in your question you will have to use Platform Channels.

The platform channels can go both ways; you should be able to set it up so that your main activity receives the NFC tag present intent, and then you send a method call from android to dart. Or you could start listening from dart and then have the method return when the intent is received.

Writing to NFC is about the same, you use method channels to call across.

Depending on what you're doing, you may want to consider splitting the NFC functionality into a plugin, even if you don't end up publishing the plugin.

Solution 2

perhaps I am a little late to the party, however as I just tackled a very similar problem, I want to weigh in on this topic: So reading/writing NFC with Flutter is possible. As mentioned before you need a platform channel in order hand the command to the native system, AND an event channel, if you want to read data to your flutter app, to accomplish this task.

The best way would be, if a plugin was available to handle this, however I could not get the one which you mentioned too to work with my flutter app (specifically, because I tried with IOS and swift). However here are some ressources, from which I puzzled together my system:

  • Communication from flutter to native system via platform channels: This link is the offical flutter page which interestingly only described the communication from flutter to native system, but not the other way around. For the other way you need:
  • Communication from native system to flutter app via event channels: (yes you need a different channel for the communication back to the flutter app). This example is only for android. For swift, all I could find was this ressource, which however seems to be a bit old.
  • NFC Tutorial for IOS: This is actually pretty simple as long as you have a developper account. A good minimalistic tutorial can be found here
  • NFC Tutorial for Android: This is actually even simpler, as nfc is longer established on android. I like this one
Share:
12,992
Zveratko
Author by

Zveratko

#SOreadytohelp

Updated on August 21, 2022

Comments

  • Zveratko
    Zveratko over 1 year

    I'd like to give a try with flutter, but so far I have found only NFC reader plugin. I will need two other things.

    • react on NFC tag present intent and then maybe use NFC plugin to read it

    • write to NFC tag, probably using Platform channels

    I just need to confirm it is feasible at all with flutter and will need the kick in the right direction, before I will leave plain android.