Flutter is a cross-platform development framework made by Google to permit a single codebase for the two iOS and Android applications.
Flutter is Google’s free and open-source UI framework for creating native mobile applications. Released in 2017, Flutter allows developers to build mobile applications for both iOS and Android with a single codebase and programming language. This capability makes building iOS and Android apps simpler and faster.
The Flutter framework consists of both a software development kit (SDK) and their widget-based UI library. This library consists of various reusable UI elements, such as sliders, buttons, and text inputs.
Developers building mobile applications with the Flutter framework will do so using a programming language called Dart. With a syntax like JavaScript, Dart is a typed object programming language that focuses on front-end development.
My sample flutter web app : https://fir-example-6ce04.web.app/
Although Flutter is a newer cross-platform framework, more and more companies have chosen Flutter over frameworks such as Xamarin, Cordova, and React Native.
Some of the top reasons why development teams choose Flutter include:
- Increased productivity. Using the same codebase for iOS and Android saves both time and resources. Flutter’s native widgets also minimize time spent on testing by ensuring there is little to no compatibility issues with different OS versions.
- Easy to learn. Flutter allows developers to build native mobile applications without needing to access OEM widgets or use a lot of code. This, in addition to Flutter’s particularly appealing user interface, makes the mobile app creation process much simpler.
- Great performance. Users report that it is difficult to notice the difference between a Flutter app and a native mobile app.
- Cost-effective. Building iOS and Android apps with the same codebase is essentially building two apps for the price of one.
- Available on different IDEs. Developers are free to choose between Android Studio and VS Code to edit their code on Flutter.
- Great documentation & community. Flutter has many great resources to answer your questions, thanks to its ample documentation with easy-to-follow use cases. Flutter users also benefit from community hubs like Flutter Community and Flutter Awesome for exchanging ideas.
The Flutter framework presents exciting opportunities for mobile app developers and businesses alike. Building iOS and Android applications with the same codebase on a highly user-friendly interface makes mobile app development fast and cost-effective.
Flutter can communicate with Kotlin or Swift code through a messaging system called platform channels. The memory of the data in Dart is directly accessible to the platform embedder (as unique pointers and direct bytebuffers). A platform embedder (written in Objective C for iOS and Java for Android) is a component that contains the bridge code for communication between flutter engine and native platform apis. This communication does not add memory overhead.
Rendering
Unlike other frameworks, Flutter does not depend on Android or iOS ui libraries to render. Flutter uses Skia to render directly render on the GPU. Skia is a 2D graphics library that calls Metal/OpenGL apis to draw on iOS and Android. Skia apis are not exposed to us developers. We’ve to rely on flutter ui packages for custom painting. To benchmark performance, we ran heavy animations in Flutter, Android & iOS and found the fps rate similar to Android and slightly slow when compared to iOS. Flutter does not support HAL and frame pacing which are needed for game development. Flutter depends on the platform for 3D rendering, video playback and to capture frames from the camera. Flutter also does not have implementation like sqlite and depends the platform for all database requirements.
Isolates
Dart provides isolates for asynchronous jobs and unlike native threads, isolates do not share memory. Dart isolates have their own private heap, that are independent of each another. It’s hard to code a memory leak or data race conditions in Flutter when compared to Android. The communication between two isolates or with main UI isolate happens through a messaging system similar to platform channel.
GC
Both Android and Flutter have similar garbage collection strategies. The framework is designed to allocate short lived objects (ui widgets) so that it works well with a generational GC. The restriction on isolate memory sharing makes it easier to track the heap and when GC is running on one isolate it would not pause another isolate. The older generation objects are collected through concurrent Mark and Sweep strategy and the new generation is collected through Cheney’s algorithm.
Flutter as independent component in Android Screen
Other companies (Alibaba, Bytedance) have tried fusing Flutter and Android, that is having Flutter view on one screen and native view on another/having both Flutter and Android components on the same screen. This involves creating multiple flutter engines. In myexperiment, I was able to paint sheet grid on a single view using 4 flutter engines. Engine to engine communication is similar to isolate-isolate communication. However engines are memory intensive and slows down app performance.
Compilation
Flutter performs JIT compilation for development builds. For release builds there is no compiler, interpreter shipped as part of the Dart VM. The app code written in dart is compiled into executable shared object files containing machine code. The final flutter apk/ipa contains our app code as .so files, engine, precompiled dart runtime (isolates, gc, dart io), dex files of our native libraries, the embedder which communicates with the platform. All these components adds 5–8mb to app size.
Follow me for more updates like this.
Thank you for reading, have a pleasing day !
Comments
Post a Comment