Flutter is an open source cross-platform application framework created by Google used to create applications for mobile, desktop and web from a single code base. It sounds like a very interesting proposition: write once, run everywhere. The question though is how Flutter behaves when we need to create more than a web-like experience.
For example, what happens when we need to use an iPhone’s Near Field Communication (NFC) capabilities? NFC is a set of communication mechanisms between two electronic devices over a distance of about an inch-and-a-half (4 cm) or less. It enables contactless payments using credit cards or smartphones.
To answer that question, we’ll do a little test.
Software and Hardware Set-up
We need at least two NFC-enabled endpoints for this project. One is the iPhone XR, the other is the NFC Dynamic Tag evaluation board. The firmware was pre-installed and the source code is available from the website, as well as the mobile application.
The Flutter environment installation for MacOS is fairly straightforward and instructions can be found here. (Note that Xcode also must be installed, but that’s necessary for any iOS development.) IntelliJ IDEA by JetBrains and VisualStudio Code by Microsoft are good choices for Flutter IDE. Xcode can be used as an editor but it does not support Flutter updates nor hot reloading, to name a few.
Flutter Packages and Plugins
There are many packages in the Flutter and Dart ecosystems. Packages may contain code, resources, images, tests and the like. A plugin package is a type of package that makes platform functionality available to the app. Usually the term is shortened to just plugin.
It is convenient to have access to a number of different packages. But at the same time, the quality of packages can be uneven, as well as license terms, development continuation, bug fixing etc.
As you can see, there are 64 packages that have NFC in their name and/or description. The top one called nfc is still version 0.0.4, last updated three years ago. Nfc_manager package on the other hand is active, and it was updated in June. We’ll use it.
Building and Running the Application
The nfc_manager package has its own demo app, which is a good sign. iOS app signing is the only part that requires attention. There is no need to sign an app if it runs on an iPhone simulator, however we can’t test NFC on the simulator.
The usual procedure is to load the project on Xcode and let Xcode manage all the signing. In my test, this part worked too. All the signing certificates were created after updating TeamID, developer ID and app ID.
However, Xcode could not properly resolve Flutter package dependencies. There was no apparent reason for this behavior, and I could not find a reason or a fix for this. I decided to use Xcode command line tools to see the output messages, and to my surprise the build completed successfully!
Note that Xcode IDE could not resolve dependency even after a successful build using command line tools. It isn’t a show stopper, but unpleasant nevertheless.
I was able to deploy and run the app using Visual Studio Code. There was no need to debug it — it just worked. I could read data from and write data to the smart tag over NFC.
Flutter is a viable tool for mobile development. The development cycle could be different from native iOS development, especially UI coding. At the same time, the NFC plugin was readily available thanks to the vibrant ecosystem. I was able to accomplish the task with very little code. As there is a choice of high-quality tools supporting Flutter development, I would seriously consider Flutter for iOS-only projects, and it will be my choice for iOS and Android projects.
I want to acknowledge the contributions of my fellow ICS engineers Jose Neto and Michal Policht who did the heavy lifting related to Flutter development.