Flutter: MissingPluginException when calling plugin from isolate spawned by native code - flutter

I'm building a Flutter app that will have the capability to execute some actions when the device connects to another bluetooth device. This app should work on Android and iOS but for the sake of simplicity I'll focus on Android in this post. Also, this has to work whether the app is in the foreground, in the background or killed.
Here is the architecture of the app:
I have an Android native code that registers to bluetooth events through a BroadcastReceiver.
I followed this tutorial to set up the communication between the Android code and the Flutter code: https://medium.com/#chetan882777/initiating-calls-to-dart-from-the-native-side-in-the-background-with-flutter-plugin-7d46aed32c47.
When the Android BroadcastReceiver is triggered by a bluetooth event, the information is sent to the Flutter code (even if the app was in the background or killed). A Flutter isolate is created to handle the Flutter code.
Everything works perfectly well. The Flutter code is called and I can use print(data) to log the data that have been provided by the Android code.
Things are becoming more tricky when, from the isolate, I want to call any Flutter plugin (like sqflite, package_info_plus, ...). I get this error every time:
[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception:
MissingPluginException(No implementation found for method xxx on
channel yyy)
I understand that spawned isolate can't natively run Flutter plugins. There are some posts (Unable to understand Flutter Isolate workaround for "'Window_sendPlatformMessage' (4 arguments) cannot be found" error, https://github.com/flutter/flutter/issues/13937) that explain how to create isolates that can run Flutter plugins by using a workaround or a plugin like https://pub.dev/packages/flutter_isolate.
However, I can't create the isolate with this package because the isolate is created from the Android code.
Can one of you tell me how I can achieve this? Is there a way to use Flutter plugins from an isolate that has been created by native code?
Thank you very much in advance

Sounds like the way you create the Flutter isolate may not be compatible with your goal. There are some solutions to integrate Flutter with native Android/iOS projects, such as flutter_boost (disclaimer: I have not tried it and not sure good or not; you may find many other alternatives as well, this is just an example). You can use that to create the Flutter environments. Since the solutions above allow some Android code to open a new normal Flutter page and Flutter code in that page is able to do anything (of course include calling native - otherwise things like flutter_boost is really useless), this should work.

Related

I am trying to cast videos from my app to chrome-cast devices

Hi I am trying to cast videos from my flutter app to chromecast devices using this plugin called flutter_video_cast from pub.dev
But the issue is while I am trying to setup these plugin for android. The instruction given by the developers in not clear due to these I am able to use it in my app.
The section which I need clarification is this part
I am not able to get what it meant by initialize cast context by extending flutter fragement activity.
Any sort of answers will be helpful for me.

Do iOS and Android Flutter widgets also work on Flutter Web(PWA)

I'm interested in using Flutter primarily for my startup MVP on Web and possibly Android. I see the flutter community has made a lot of widgets but a lot of them are tagged iOS or Android. Since Futter is all about using one codebase is it wrong to assume that these widgets would work on web too? I imagine the setup would be different but similar with a Flutter web app as opposed to a Flutter Android app.
I couldn't find a whole lot about this on the Flutter site. I also know that web is still beta but by the time I'm done with the MVP it'll probably be at stable release or close enough.
Well... It depends. If the widget has some sort of native code the answer is no. In Flutter there are two type of packages: the "normal" package, and the plugin.
The packages are made only of dart code, so there are no bounds to native, and you can use everywhere dart (and Flutter) can run.
The plugins are packages with native code and you can use only on the platform supported by that plugin.
For example the package provider, it's a package, and you can use in every supported platform where dart (and Flutter) can run. But url_launcher, it's a plugin, so you can run only on Android, iOS, and web, but for example on desktop, it will no work.
If the package if you found it's only a widget, you should be able to use on the web.
TLDR: No,a PWA it's a web app, so it can't run Android or iOS specific code.

flutter P2P communication over the network

I read this Android specific article and was wondering if some applications existed for Flutter aswell.
I know it is possible to run native code in Flutter, but I'd prefer a Dart native solution. I've noticed this package on pub.dev but I cannot make it work.
I've followed the posted example but I get a MissingPluginException for every call the plugin executes.
Yes You can do it by using this package .
https://pub.dev/packages/flutter_nearby_connections

Is there any way i can buid an android app/content blocker in flutter

I am trying to create an android app that can block content/apps whenever something happens but i cant find any documentation in Flutter. I understand that what i want to do is more of native. Any recommendations.

Flutter : Run an app as a background service

I want to show a custom popup message whenever the user disconnects a cellular call. The problem is how to detect when the app is not running. any leads would be helpful.
It's been a while and there have been many developments.
First, there are some answers at How to create a service in Flutter to make an app to run always in background?
Also, flutter/Background processes will basically point you to medium/Executing Dart in the Background with Flutter Plugins and Geofencing (Sept 2018)
which is a Geofencing sample that involves a partnership between isolates, native Android/iOS code via MethodChannel, and PluginUtilities.getCallbackHandle (PluginUtilities)
Alas, there are many plugins available now:
https://pub.dev/packages/background_location
https://pub.dev/packages/android_alarm_manager (Android)
https://pub.dev/packages/background_fetch
https://pub.dev/packages/workmanager
https://pub.dev/packages/audio_service