When you enable Flutter Windows support, you create a Windows folder for your list of projects. Inside the folder are the Cmake project files. When you execute Flutter Run, if you open Vs2019, you will see the Cmake working content on the console below.

Out of curiosity, I sorted out the contents of the folder and summarized the following flow chart:

Without saying more, start analyzing step by step!

main.cpp

Lines 20-33 are the start logic of the Flutter. The remaining heads and tails correspond to the start and end of the flow chart. We don’t care about this here.

If you’d like to take a closer look at the internal logic of DartProject and FlutterWindow, the following article goes through the internal processes in detail, but is separated out because there is too much space.

How does the Flutter Engine start on Windows? (Haven’t started writing yet)

Only CreateAndShow of FlutterWindow is combed here

CreateAndShow(FlutterWindow.cpp)

The parent class of FlutterWindow is Win32Window. Win32Window is not complicated. The CreateAndShow function is actually implemented by Win32Window.

CreateAndShow (title) CreateAndShow (origin) CreateAndShow (title) CreateAndShow (origin)

Before the Oncreate function is called, the students familiar with Win32 MFC already know, set DPI, create a blank window, use Win32 HWND identifier to store the window information, currently this window is blank.

At this point, I still do not see any startup code for the Flutter Engine, so at this point, the Flutter Engine has not been started.

OnCreate(FlutterWindow.cpp)

high energy alert

Win32Window’s OnCreate is a flop, FlutterWindow’s OnCreate is a heavyweight.

  1. In line 19-26, Flutter_controller_ is of type FlutterViewController and the construction parameters are the window size and DartProject, meaning that the project we originally created will be used here. This controller helps us deal with a lot of internal logic, but basically it helps us start the engine. Want to dig deeper? The following please… (Same article as above)

    How does the Flutter Engine start on Windows? (Haven’t started writing yet)

  2. Lines 24-26 check whether the initialization is successful.

    • In general we writePlatform ChannelThe configuration of the engine is also in this function, because it ensures that the engine initialization is successful.

    Flutter interaction with Windows Platform (Method&Event Channel) – Nuggets (juejin. Cn)

  3. The FlutterViewController holds the view and the Flutter engine that display the screen. The View’s GetNativeWindow method returns an HWND identifier that corresponds to the flutter rendered interface.

  4. Finally, call Win32 MFC SetChildContent to replace the original blank content with the desired Flutter interface.

Back to the main CPP

CreateAndShow returns true to create a screen.

Write thoughts

No one will study this, but I am the first iron to study, because from the cloud, LET me see the feasibility of shared texture, eat through a platform, other logic is similar, hee hee.