Rapid prototypes on Flutter and Kotlin / Native

Original author: JB Lorenzo
  • Transfer

Rapid prototypes on Flutter and Kotlin / Native


Having received the task of developing an application for our upcoming internal conference within the OLX Group, my team thought about how to reduce the time to create an application for iOS and Android, because we had nothing to do without it. The first thing that occurred to me was to use Kotlin, because It can compile on other platforms. Spoiler: not everything went as originally planned, but we did everything on time, learning many new things along the way!


So, this is a story about how we made the OLX Group Product & Tech Conference application in record time.


Recently, companies such as Google and Facebook have made great efforts in the development of cross-platform development. Flutter and Kotlin / Native are the results of these efforts.


What is Flutter?


Flutter, developed by Google, was announced in 2017. As a development language, he uses Dart. Flutter supports compiling code on both Android and iOS using the same code base written in Dart. Flutter is compiled into native code, and does not use web view components in applications. But it uses its own user interface components instead of platform-specific UIView-like in iOS or Fragments and ViewGroups in Android. Flutter also supports Material Design and Material Theming in its user interface components.


We had no experience with Dart development, so we were not sure that we would have enough time to learn a new language (after all, we had other priorities). We really did not start using Flutter until we realized that we really have little time. Therefore, we initially started with the use of Kotlin / Native and developed some model data and logic for them.


This is the folder structure in Kotlin / Native we had:


Folder structure in Kotlin / Native


Pay attention to the “common” folder where all common code written in Kotlin is placed. Accordingly, projects on Android and iOS use the code from this folder.


What is Kotlin / Native?


Kotlin / Native is developed by JetBrains, the same company that created Kotlin. If you have not heard of Kotlin, perhaps you just recently did not go online. In general, this is a simplified replacement for Java, which also supports backward compatibility with it. Kotlin / Native allows you to write code on Kotlin and compile it on various platforms that do not natively support Kotlin, for example, iOS.


Design


We asked our designer to lay out some kind of layout for the application, and she quickly made a nice design with the help of Material Theming. The Sketch there is a plugin for creating thumbnails Material Theming, which saved us a great deal of time and effort.


Here is a brief overview of the sketch designs made by our designer:


Thumbnail overview


Material Theming allows you to quickly create design layouts and supports both iOS and Android.


Initially, we wanted to implement the user interface separately for Android and iOS. Despite the fact that both platforms support Material Theming, we would still have to write interfaces for both. And we thought that if we use Flutter for the user interface, we will have one code base for it and it will be independent of the application logic, and accordingly we can continue to use Kotlin logic regardless of this.


Teach Kotlin / Native and Flutter to work together.


Because before that, Flutter and I did not work, we needed to make sure that it would work with existing code that we already have. By the way, it seems that before that no one tried to use Flutter and Kotlin / Native together. We planned to build the architecture shown below. This architecture reduces the amount of code specific to each platform, and also reduces the amount of code on the Dart, since we can isolate most of the logic using Kotlin.


Application architecture


We were able to reduce the amount of specific code using Kotlin and Dart. Because Since we were more familiar with Kotlin, then most of the common code was written on it, and not on Dart.


application


Restrictions


Both of these technologies have certain limitations that make using them not as simple as it could be.


Restriction 1: Kotlin / Native only supports Kotlin classes for common code. For example, if you wanted to use java.util.Date, then you would not have such an opportunity, because it requires a JVM. One way to solve this problem is to implement this method in the platform code (Android and iOS) and call it from Kotlin / Native.


Restriction 2: Kotlin uses Companion objects for static methods that turn into a completely new object in iOS. One way to get around this is to do static methods with instance methods or make a class method a global function.


Restriction 3: Kotlin / Native only supports compilation for arm64 on iOS. The latest devices work with this processor architecture, but the old ones are still on armv7. To avoid any problems with the architecture, simply go to “Build Settings” and delete all architectures except arm64.


There are also some limitations in the interaction between the Kotlin code, Flutter code and platform code. Flutter can interact with the platform code using channels, passing the method name and a set of parameters there. Parameters are limited to native classes such as map, list, string, int, etc. With all this interaction, custom objects are serialized. However, both Flutter and Kotlin / Native support serialization rather limitedly, so for now we are using native classes directly.


Results


Key results of our experience:


  • Flutter is great for fast prototypes;
  • Flutter and Kotlin / Native are still in beta testing, but can already be used, albeit with some restrictions;
  • Kotlin / Native perfectly solves the problem of reducing the number of platform-specific code;
  • You need to write some layer, which will be responsible for the transfer of objects and their serialization.

It took about a week of planning and a week and a half to develop the application. We spent about an hour a day on this with four developers and a designer, while at the same time doing our usual work.


It was a lot of fun to develop this application using Flutter and Kotlin, and I hope that you will also try these two technologies.


IOS application


You can find more materials on Kotlin / Native in the official documentation:



And read / watch about Flutter here:



Also popular now: