FlutterPlugin vs FlutterActivity - flutter

for my Flutter App I want to write myself a small plugin which is using the camera natively in Android.
I was going through the documentation, and I got a basic understanding of the "glue" between Flutter and Native with MethodChannels. There is one thing I don't understand though:
What exactly is the difference, if my native class of the plugin is implementing a FlutterPlugin and ActivityAware, or if I use An Activity directly which is extending FlutterActivity and also connecting to the Flutter engine?

Related

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

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.

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.

How to make Modularization in Flutter to separate each application feature

On Android native to separate each application feature, structured the project, implementing architecture component and to make it easier to work in a team you can use modularization, so each person can focus on their respective work by focusing only on the module. If I want to make a flutter application with examples of 3 application features (login, register, profile) and want to implement modularization for each feature to make it easier to work as a team. How do you implement the modular? Are there references to its best practices for modularizing Flutter? Because if on Android Native there are already many related articles while I check for Flutter it hasn't found it yet.
Create each feature as a package(library) and add it whenever you want to the main app. For example in my app I use main.dart as a navigator manager and each screen is in different packages.
And this is an example of implementing it: https://github.com/rrifafauzikomara/flutter_modularization

The docs of firebase-app-indexing are silent on Flutter implementation

Is it just a matter of following the android and iOS settings or are there ways to make it a bit easier for those who are building apps in Flutter?
An example of a Flutter implementation of firebase-app-indexing would be fantastic.

Flutter - Android Native Platform Integration

When an external component such as a Camera or File picker is needed, the Flutter for Android Developers documentation (currently in the works) states that we would have to build a native platform integration.
I currently have a device that has a built-in barcode reader with a manufacturer-provided Android API. So, for that I would need to pursue this native platform integration method - or even for playing videos or using the camera for that matter I would think.
Is there an example repo that demonstrates how a well-integrated app should be? ..a project that integrated ExoPlayer for example?
You can use platform channels to call native APIs that aren't exposed by the Flutter platform.
There is an example in the Writing custom platform-specific code docs:
The full, runnable source-code for this example is available in /examples/platform_channel/ for Android with Java and iOS with Objective-C.
If you want to make your code reusable by others, you can publish it as a package, but this is optional. There is a repo of plugins maintained by the Flutter team that you can use for inspiration.