I am trying to make a cross platform IoT device that uses USB Serial protocol (RS232). For that, I am using the native library that is only meant for Android along with serial (web library for supporting Mac, Linux and Windows).
I have created two separate files where the drivers work well with my device independently, but I don't want to keep the codebases separate. But when I combine them and use them, it won't compile for Android and Web saying that you cannot use html on flutter without web and cannot use a dependency for Flutter not meant for web.
Any clue on how to solve this? I'm using provider for state management and passing callbacks for the UI to access device data (might shift to Riverpod in the coming future).
Related
How can I access device information without using packages in Flutter? How can I get the information of the device where the app is installed in my Flutter app?
First, you'd be better off using packages. But if you really want/need to do it, you'd have to write platform-specific code code in the native language of the targeted platform (ie. Swift or Objective-C for iOS/Mac, Kotlin or Java for Android, etc), then use so-called platform channels to pass messages between your app and the platform-specific code.
If you'd like to get details about the device, on iOS you'd use UIDevice, on Android you'd typically want Build.
This can only be done through Method Channel
I am a flutter developer, I want to make an application to exchange messages and files by using NFC technique
I used nfc_in_flutter plugin for reading and writing NFC tags but I don't know how to send and receive data and files between devices by using NFC in flutter.
Could any one help me, please?
Generally you don't try and send data between 2 devices using NFC, there is a standard for it, but most devices don't support it (it has never been supported on iOS and Android has dropped support for it as it was unreliable)
Use Bluetooth or Wifi Direct instead.
Update:
If you have to use NFC then the nfc_in_flutter plugin is no use, you are going to have to call native code for each platform yourself / write your own plugin.
And for 2 iOS devices, then forget it, just not possible because of what the OS supports.
When one device is an Android there is a complicated method that some people have had some success with but it still has it's issue.
The Android device does Host Card Emulation (HCE) and pretends to be a really Type 4 NFC tag, then other devices can read/write to it as if it were a real Tag which both iOS and Android Support. BUT on older Android devices then the deprecated Android Beam might get in the way and you would need to use enableReaderMode to do the read/write on Android.
You will need to put in a lot of error handle in the read/write App as NFC comms is very slow and very prone to loosing the connection, so it would have to handle loosing the connection and restarting where it last successful read from/written to.
All these problems make this extremely difficult to achieve a workable solution and was the main reason Google removed Android Beam for Android to Android sharing (which does use a NFC peer to peer protocol)
We have a single codebase for Android & iOS in Flutter.
We tried to use the same codebase for Web in Flutter too, but it hadn't gone well.
As of some libraries/plugins, currently unsupported by Flutter SDK.
To mitigate these issues, we are maintaining two separate repositories, one for Android-iOS and other for Web.
Also, to add up here, for separate repositories because each Flutter product has a unique pubspec.yaml file. Now there are a few plugins that are currently supported in App but Not yet on Flutter Web, namely Awesome Notifications, Clevertap plugin, etc.
Integrating those plugins on the web, stops the web to run. So keeping the same codebase for both is getting technically complicated as the app has many many functions.
It takes so much time in simultaneously testing, debugging and resolving issues in Web.
So, how we can maintain same code for all platforms i.e., Android, iOS & Web, without doing it in other repository for Web and gaining advantage in streamlining our codebase into one for all platforms?
For Ex. If I commented the package awesome_notifications for Web in pubspec file, the issue arises (as shown in the screenshot) in code wherever we used its functionalities.
For successfully working on both Mobile & Web, are there any methods available we can use packages for both (Mobile & Web)?
Ideally you’d want to use a single codebase to host both the web and mobile versions, to minimise code maintenance and improve efficiency. To do this, you’ll need to be able to find the platform the code is running on, so that code can be called programmatically.
You can use the constant kIsWeb to check if the application is compiled for the web, and you can then use that condition to only run platform-specific code (such as the awesome_notifications package) if you’re on a platform that supports it. That way you’ll still be able to import the required packages, but only call them when the app is running on the mobile version of your app.
That should allow you to condense your codebase into one repository without sacrificing any functionality that may not work across all platforms.
What I want is to make a web/mobile app (I've chosen Flutter) that acts both as a host and as a client, so multiple instances of this app can share data without actual back-end (let's say the addresses of the devices are hardcoded into the app for the simplicity).
I can't use Firebase or Backendless, my app has to be the only host.
I've looked into socket.io, websockets, WebRTC and didn't find a solution.
So, is it even possible? With or without Flutter.
It is in theory possible, if you are planning to only use android you can use this library Flutter p2p which use wifi-direct (Android documentation) to discover devices and connect to them. It has some problems with newer environments but there is lots of forks from the git project that you can import. I've read that it should be possible to allow devices that doesn't support wifi-direct to connect if you create a group so maybe it could work for iOS if there is a hosting android device.
I am trying to build a project based on IoT with flutter, android things, and raspberry pi. For that, I need to access raspberry pi GPIO pins through my flutter app.
Firstly I have installed android things os onto the raspberry pi and connect a display to it. After that, I have to build a flutter app and uploaded and it's working perfectly but now I need to control GPIO so I have googled it but found nothing except the rpi_gpio dart library which can access raspberry pi GPIO pins but apparently it is not working on flutter dependencies.
So is there a way then suggest me so that I can complete my project.
I know that this posting is a bit old, but another option might be to use the pigpio library. It has a feature that pushes the entire API out to a network connection (this feature is called "pigs").
I struggled trying to use FFI to interface with the C-based pigpio library on a Pi Zero W. Then I was reminded that Dart support for the older, less powerful devices had been dropped from Dart, so I was stuck with no graceful solution until I tried out pigs. The pigs interface completely removed the headaches associated with either FFI on Dart or JNI in Java and just made it a happy Socket interface over the network. I was doing an I2C interface to a temperature/humidity sensor. Pigs should also make a browser-based Flutter app happy as long as you deal properly with the single origin requirements.
Here's a link to pigs on pigpio
I've recently seen a Dart library for the Raspi's GPIOs. As Dart is the underlying language of Flutter, shouldn't you be able to then use the pins by importing this library?
https://pub.dev/packages/rpi_gpio
As far as I know there is no plugin for Flutter to interact with Peripheral IO. Given Flutter's nature of targeting multiplatform and Android Things being very specific, I do not think something like that will exist.
Most IoT applications have quite simple logic, so it should be reasonable easy to write the UI on Android directly (given you are not planning to release in any other platform anyway.
Your other option would be to create a Flutter plugin for GPIO and port it only to Android, but IMHO it will be harder to do than just code the UI of the app directly on Android.
There is now another FFI-based gpio on RPI Dart package called gpiod.
Its use is described in this article on running Flutter on a RPI based device.