Flutter Can Migrate Exiting Native App Code into Dart?
Chirag Jadav
AI & Mobile App Specialist | Transforming Ideas into Scalable MVPs & Intelligent Solutions | Full Stack Development Expert | React Native | Flutter
Migrating to Flutter
Flutter, Import from Exiting Android Project
If you guys are like me and you always want to keep step with latest and best technology available out there then you are already thinking about migrating to Flutter for your new mobile applications. Some of you already tested Flutter, some of you only heard about it and some of you already think about migrating your applications from Java and Kotlin to Dart powered Flutter.
No, you cannot convert your existing Android code into Dart code for Flutter, which is necessary to enable cross-platform behaviour because all code used by the Flutter SDK has to be written in Dart.
However, you could make use of your Android code by just including it in the Android folder and trying to integrate it with the Flutter SDK, which will probably be all lot more work than just rewriting it entirely in Dart. This is also not what you generally want to do because native Android and iOS code make most sense to be used to enable features that you cannot achieve with Flutter, in the form of plugins.
There is also a third approach, which is that you keep your Android code and only add features with Flutter. This is harder to implement because you will have to create an interface to "switch" to Flutter from Android code. Using this you would also need to rewrite your remaining parts for iOS in either Flutter or native iOS, which does not help you at all.
There is a pretty straight forward answer to this.
Flutter is a layer on top of the native SDK's. This means that you could keep your code because, if you ever took a look into a Flutter project, you would see that in it there are, at the moment, essentially three structures you can work with:
- lib folder for Dart code + files Flutter needs to e.g. include plugins, short: Dart code forFlutter
- iOS folder for either Objective-C or Swift code, which also includes the usual iOS accessories
- android folder for either Java or Kotlin (or C++) code and all other gradle files etc.
This means that you can use native code if you want to, but you do not need to do it.
You can completely ignore the android and ios folders during development if you want to`.
Most likely you will just be modifying aspects like the app icon, name, version name, license keys etc. in your native code.
Flutter's goal is to write all code in Dart and only in the Flutter SDK, which means that your existing Android code could be included in the project, but it will not have any use for iOS because all cross-platform work is done in Dart making use of the Flutter SDK.
Conclusion
If you really want to switch to the Flutter SDK, your best choice is entirely switching to Flutter, i.e. rewriting all features in Dart.
There is no "import" possibility to "convert" Android code to Flutter code. This would not even work if they were written in the same language because the Flutter architecture is completely different and the way you build apps is not remotely related to Android applications.
If you think that learning Dart and rewriting your application for cross-platform is not worth it but you still want iOS support, I would suggest you to write in iOS native, but my general suggestion for the problem is rewriting the whole application in Dart.
Next time mention where u copy the article from. Copied from stack overflow
Microsoft Dynamics 365 Administrator | Microsoft Office365 Administrator | Azure Administrator
5 年Is flutter Better than react native?