The Flutter Engine Source (1)

As you know, flutter is a multi-platform ui engine for mobile, desktop and web, the flutter engine architecture is like this.

Flutter Architecture Diagram
flutter system

On the bottom lies the embedder which creates the threads and surface for the engine.

So take the iOS platform embedder for an example, here how the embedder creates the underlying support for flutter.

What embedder does:

create the Shell object defined in src/flutter/shell/common/shell.cc

This is the object that is at the core of flutter engine which handles ui rendering, platform messaging and flutter engine creation.

Let’s look at the comment section for this class,


Perhaps the single most important class in the Flutter engine repository.
When embedders create a Flutter application, they are referring to the
creation of an instance of a shell.

Creation and destruction of the shell is
synchronous and the embedder only holds a unique pointer to the shell. The shell does not create the threads its primary components run on. Instead, it is the embedder’s responsibility to create threads and give the shell task runners for those threads.

This basically tells us that the creation of the flutter engine means the creation of the Shell object by the embedder.

So let’s begin digging into the shell creation process.

There’s two things the embedder has to provide,

  1. a surface for drawing
  2. an engine for dart code execution.

1.The initialization process

This part is where dart:ui draws the app. The embedder has to provide a surface for the skia 2d engine to draw the flutter app.

on iOS platform, the surface is a FlutterView class, which is held by the FlutterViewController class, which itself is held by the AppDelegate of the App.

when the app launches, the flutter ViewController’s designated initializer is called by the storyboard,

- (instancetype)initWithProject:(nullable FlutterDartProject*)project
                        nibName:(nullable NSString*)nibName
                         bundle:(nullable NSBundle*)nibBundle

in this method the engine is created and [_engine createShell:nil liraryURI:nil]; is called for shell creation.

this method in turn calls the c++ method flutter::Shell::Create()

this c++ method handles the task runner creation,

platform/gpu/ui/io,

in convention the platform and gpu task runner are the same.


Then in FlutterViewController’s viewWillAppear: method, flutter engine will be set to launch, which performs the following steps,

  1. check configuration valid
  2. get entry point?
  3. check isolate run status PrepareAndLaunchIsolate(config)
  4. if isolate running add settings’ callbacks to isolate
  5. get service id and handle platform service id messge

I’m still figuring out the calling stack and details of the running process so,

article to be continued …