flutter: what's the role of FlutterEngine?

656

Flutter implements most of its system (compositing, gestures, animation, framework, widgets, etc) in Dart. Flutter engine, written in C++, is designed to interface with the underlying operating system.
Flutter architecture consist of three layers

  1. Framework
  2. Engine
  3. Embedder

First you need to understand how flutter renders your app on a very high level, rendering in Flutter goes through four phases:

#1. Layout Phase: in this phase, Flutter determines exactly how big each object is, and where it will be displayed on the screen.
#2. Painting Phase: in this phase, Flutter provides each widget with a canvas, and tells it to paint itself on it.
#3.Compositing Phase: in this phase, Flutter puts everything together into a scene, and sends it to the GPU for processing.
#4. Rasterizing Phase: in this final phase, the scene is displayed on the screen as a matrix of pixels.
To go in-depth refer this article on medium.com

The engine is responsible for rasterizing composited scenes whenever a new frame needs to be painted.
Another thing to note is that Flutter neither uses WebView nor the OEM widgets that shipped with the device, rather it uses its own high-performance rendering engine to draw widgets which is Skia (a 2D graphics rendering library)
link to flutter official FAQ page
In a nutshell
It acts like a bridge, whatever dart code you write gets converted to C and C++ and compiled with Android’s NDK(incase of android) and LLVM(incase of ios) "ahead-of-time (AOT)" and guess who is responsible for this?..... yes flutter engine.
Also I highly encourage you to read the official Docs.

Share:
656
byhuang1998
Author by

byhuang1998

Updated on December 25, 2022

Comments

  • byhuang1998
    byhuang1998 over 1 year

    I'm learning about flutter architecture. I couldn't understand FlutterEngine well and haven't found any clear explanation. So what does FlutterEngine work for, or could you introduce some good article for me? Thanks in advance.

  • Christopher Moore
    Christopher Moore almost 3 years
    Those last few lines are wrong. The Dart code you write is not converted to C&C++. The engine itself is written in C&C++, which is compiled with NDK or LLVM. There is no conversion process from Dart to C/C++. Your Dart code is AOT compiled when you build your app, but it then needs a Dart runtime(which is provided by the engine) for it to be executed.