'Adding native Android code to a Flutter app

I'm trying to add native android code to an already existing Flutter app, that does something quite different. So I'd just like to have all of that functionality on top of my current app. The native android app is using Bluetooth to connect to an external device and is collecting data periodically.

I know, that there is the possibility to call native code via platform channels, but it seemed to me, that you'd have to call that code every time you want to use it? Is this a reasonable way to implement the app or should it be rewritten in Dart? What's the best practice here?

Hope you can help me, thanks a lot!



Solution 1:[1]

The purpose of platform channels is to call platform-specific APIs.

...you'd have to call that code every time you want to use it...

Correct.

...Is this a reasonable way to implement the app or should it be rewritten in dart? What's the best practice here...

Check the source code of any package that relies on platform channels (for example camera, file picker, etc.) and read the official documentation. As a short summary, platform-specific code is written in Kotlin/Java (Android), Swift/Objective-C (iOS) or C/C++. Dart is used for building the UI and communicating with said code via platform channels and messages.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sunderee