Reputation: 17
I need to migrate my old native apps to flutter and i am considering leaving the business logic on native. Is there a performance overhead in the communication between the flutter and native?
Upvotes: 0
Views: 377
Reputation: 10186
For purposes of sharing state between the native code and dart code, MethodChannel
s are likely performant enough. But there are enough non-performance drawbacks to make it worth avoiding if at all possible:
You will still need to manage state on the Flutter side. Whether you use bloc
, provider
, or simply a StatefulWidget
, you will need to hold your data in Dart's memory. If your state changes on the native side, you are responsible for updating that state on the Dart side. Having 2 copies of all of your state is likely to be a source of bugs, since you now have 2 "sources of truth".
You will (potentially) get different behaviour on different platforms. If you have a bug in the iOS native code but not in the Android native code, for example, you may never encounter it if you develop/debug on an Android device. Having all of your business logic in Dart means that instead of having to trust that you implemented the same logic correctly both times, you only have to trust that the Dart compiler "works" (personally, I trust the Dart team far more than I trust myself, and if I didn't, I probably wouldn't use Flutter).
It will be harder to test. Widget testing is a very nice feature of Flutter, since it allows you to simulate a portion of your app inside a test method and verify that you get the behaviour you expect, without the overhead of launching the full app, launching an emulator, etc, that comes with a full-blown integration test. If you use the split approach, you lose this ability, since you won't have a native platform backing the other side of your MethodChannel
s.
If at all possible, I'd strongly recommend avoiding this split behaviour and either fully migrating to Flutter, or not at all
Upvotes: 2
Reputation: 206
Well, I'll prefer migrating the complete project on Flutter, because else you won't be using Flutter for the purpose it was built, it will more hassle for you to keep half the portion in native, Flutter does provide platform specific code and its pretty good, but we only use it when its necessary like native SDK integration etc, else invoking native method for your every business logic would be overhead.
Upvotes: 0