How does Flutter work?

Utsav Ghimire
7 min readJul 29, 2023

--

A high-level overview of the architecture of Flutter, including the core principles and concepts that form its design.

Flutter is a powerful and popular open-source framework for building cross-platform mobile applications. It works by leveraging a unique architecture that ensures high performance, expressive user interfaces, and efficient development.

At its core, Flutter employs a “widget-based” approach, where the entire user interface is constructed using widgets, representing various UI elements and layouts. These widgets are organized in a hierarchical structure called the “Widget Tree,” reflecting the current state of the user interface.

In Flutter, almost everything is a widget — even layout models are widgets. The images, icons, and text that you see in a Flutter app are all widgets.

Flutter Architecture:
It is characterized by its widget-based approach, reactive programming paradigm, and efficient rendering.
This architecture sets Flutter apart from other frameworks and contributes to its distinct characteristics and strengths. Let’s explore some key aspects of Flutter’s unique architecture:

  1. Widget-based UI: The foundation of Flutter’s architecture is the use of widgets. Everything in Flutter is a widget, representing various UI elements, layouts, and even application logic. Widgets are declarative and immutable, meaning they describe what the UI should look like based on their current state. This design allows for a more straightforward and consistent UI development process.
  2. Reactive Framework: Flutter follows a reactive programming paradigm. When the application’s state changes, the widget tree is rebuilt accordingly. This reactive approach enables a highly efficient and optimized UI update process, as only the necessary widgets are updated, minimizing unnecessary rendering.
  3. Single Codebase, Multiple Platforms: One of the most significant advantages of Flutter’s architecture is its ability to create native-like applications for multiple platforms (Android, iOS, web, and more) from a single codebase. This is achieved through Flutter’s engine and platform-specific embedding layers, which bridge the gap between the framework and the target platforms.
  4. Fast Rendering with Skia: Flutter uses the Skia graphics library for rendering UI elements, providing high-performance 2D graphics. Skia is known for its speed and efficiency, contributing to Flutter’s smooth and responsive user interfaces.
  5. Hot Reload: Flutter’s architecture facilitates the “Hot Reload” feature, enabling developers to see instant changes in the app’s UI during development. This rapid iteration capability improves developer productivity and accelerates the development process.

Let us dive deep into Flutter’s architecture.

Flutter’s architecture consists of three main layers:

  1. Framework Layer: Responsible for rendering the UI and handling user input. It continuously generates frames to update the UI efficiently and smoothly.
  2. Engine Layer: Acts as a bridge between the Flutter framework (written in Dart) and the underlying platform (Android and iOS). It includes the Flutter engine, which handles graphics rendering and execution of Dart code through the Dart VM.
  3. Embedding Layer: Platform-specific code that integrates Flutter with each target platform, ensuring the app runs as a standalone application with access to native platform features.

The combination of these layers and the widget-based approach enables Flutter to deliver high-performance, visually rich, and cross-platform mobile applications while maintaining a consistent user experience.

  1. Framework Layer: Where the Magic Begins

At the heart of Flutter lies the Frame Layer, a pure Dart-implemented SDK that forms the bedrock of this powerful mobile application development framework. The Frame Layer is where the magic happens, where developers like you build stunning, high-performance apps that run seamlessly on multiple platforms.

i. The Dart UI Layer: Animation, Gestures, and Drawing
The Dart UI Layer, also known as dart:ui, is a treasure trove of animation, gesture, and drawing capabilities. It merges the functionalities of Foundation, Animation, Painting, and Gestures, providing you with a cohesive set of tools to bring your app to life.
With dart:ui, you can effortlessly create smooth animations, define intuitive gestures, and craft beautiful custom drawings that breathe life into your UI.

ii. The Rendering Layer: Bringing Your Widgets to Life
The Rendering Layer is a critical part of Flutter’s core. This abstract layout layer builds a rendering tree composed of renderable objects, each representing a visual element in your app.
When these objects undergo dynamic updates, the rendering tree efficiently identifies the changed parts and meticulously updates the rendering. It not only determines the precise position and size of each rendering object but also handles sophisticated coordinate transformations and seamless drawing using the underlying dart:ui library.

iii. The Widgets Layer: Your Toolkit for Building Great Apps
Completing the Frame Layer is the Widgets Layer, a comprehensive set of basic component libraries provided by Flutter. These widgets are your trusty tools to design user interfaces with ease and elegance.
Flutter’s Widgets Layer empowers you with a wide range of building blocks to create UI elements, handle user inputs, manage layout, and more. With widgets at your disposal, you can quickly craft intuitive app designs, staying true to the Material Design principles with the Material library or embracing the native iOS feel with the Cupertino library.

2. Engine Layer: Unleashing the Power Within

The Engine Layer is the mighty core of Flutter, where the true magic happens behind the scenes. This robust layer, mainly implemented in C++, plays a pivotal role in bringing the Flutter framework to life. Within the Engine Layer, several critical components work together harmoniously, enabling the seamless execution of your Flutter apps.

i. Skia Engine: The Art of Drawing
At the heart of the Engine Layer lies the Skia engine, a powerful 2D graphics processing library developed by Google.
Skia is the driving force that handles the intricate task of rendering visuals on the screen, ensuring that your UI elements come to life with stunning precision and speed.

ii. Dart Runtime: The Language of Flutter
The Dart runtime, residing within the Engine Layer, is where the Flutter framework’s language, Dart, comes to life. Dart is the soul of Flutter, and within the Engine Layer, the Dart runtime interprets and executes the Dart code you write.
The Dart runtime brings to reality the logic, calculations, and interactions you define in your Flutter app.

iii. Text Layout Engine: The Art of Typography
Flutter’s commitment to flawless typography is fulfilled by the Text Layout Engine within the Engine Layer.
This sophisticated engine impeccably handles text rendering, layout, and formatting. It ensures that your text appears gracefully on the screen, regardless of font styles, languages, or screen sizes.

iv. Interacting with the Engine Layer
As you develop your Flutter app, you’ll frequently interact with the Engine Layer indirectly through the Flutter framework’s APIs.
For instance, when you call dart:ui functions, the request is directed to the Engine Layer, where the actual drawing and display of UI elements take place.

3. Embedding Layer: Bridging Flutter with the Platform

The Embedding Layer is the vital bridge that connects Flutter with the native platform of each device. It is the mastermind responsible for the final rendering and seamless interaction of Flutter apps on various platforms. When you run your Flutter app on Android, iOS, macOS, Windows, or Linux, the Embedding Layer is what ensures that your app blends seamlessly with the native environment.

i. Installing the Flutter Engine
At the heart of the Embedding Layer is the task of “installing” the Flutter engine on the specific platform. This process involves integrating the Flutter engine’s capabilities into the native code of each platform.
For instance, on Android, the embedding layer is written in Java and C++, while on iOS and macOS, it’s written in Objective-C and Objective-C++. Similarly, on Windows and Linux, the embedding layer is implemented in C++.

ii. Integration and Flexibility
The Embedding Layer empowers developers to integrate Flutter into existing applications as a modular component. You can seamlessly combine Flutter with your existing native codebase, making it easier to enhance your app with Flutter’s UI capabilities.

iii. Platform-Independent Flutter
Flutter’s versatility and flexibility are magnified by the Embedding Layer. Flutter itself contains the embedding layer for common platforms like Android, iOS, macOS, Windows, and Linux. This native integration ensures that Flutter performs optimally and harmoniously across these platforms.

iv. Embracing New Horizons
As Flutter evolves and expands its reach, the Embedding Layer plays a pivotal role in supporting new platforms. If Flutter wants to extend its capabilities to a new platform in the future, developers will craft a new embedding layer specifically tailored to that platform. This adaptability ensures that Flutter remains at the forefront of cross-platform development, embracing new horizons and possibilities.

v. A Symphony of Platforms
The Embedding Layer orchestrates a symphony of languages and technologies, seamlessly merging the expressive Dart language with the native power of each platform. This symphony allows Flutter apps to resonate with users on Android, iOS, macOS, Windows, and Linux, presenting a unified user experience across platforms.

vi. Bridging Worlds with Flutter
In summary, the Embedding Layer is the essential link that allows Flutter to bridge the worlds of native platforms and cross-platform development. It empowers developers to harness the full potential of Flutter while seamlessly integrating with the native environment. Flutter’s Embedding Layer provides a seamless and harmonious experience, uniting the power of Flutter’s cross-platform capabilities with the unique strengths of each platform.

vii. Expanding Possibilities
With the Embedding Layer as your ally, you have the power to explore new possibilities in mobile app development. Let Flutter guide your journey as you unlock the potential of cross-platform development and deliver remarkable apps that captivate users on every platform. Embrace the embedding layer, and together, let’s build a future where mobile app development knows no bounds with Flutter.

Conclusion

In conclusion, Flutter stands as a powerful and popular open-source framework for building cross-platform mobile applications. Its unique architecture, centred around a widget-based approach, sets it apart from other frameworks, making it an attractive choice for developers and businesses alike.

By organizing the entire user interface using widgets and managing UI updates reactively, Flutter ensures high-performance and expressive user interfaces. The use of Skia for rendering graphics further enhances the app’s responsiveness and smoothness.

One of Flutter’s standout features is its ability to create native-like applications for multiple platforms, including Android, iOS, web, and more, all from a single codebase. This single codebase approach streamlines development, reduces maintenance efforts, and fosters code reuse.

Source:
Flutter Architectural Overview
flutter.dev

About me?

Connect with me on Linkedin or Github

--

--