简体   繁体   中英

NFC read/write with flutter

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.

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.

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

With this fork from flutter-nfc-reader you can now read and write nfc tags from android and read them from ios https://github.com/semakers/flutter-nfc-reader

to install add the following dependency your pubspec.yaml

 dependencies:
  flutter_nfc_reader:
    git:
      url: git: //github.com/semakers/flutter-nfc-reader.git
      ref: master

In the Readme.md of the repo are the installation and use instructions.

Happy NFC Tag writing!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM