Platform Embedders Overview

At its core, platform embedding is about how Flutter interacts with the underlying operating system to display your app and handle its lifecycle. Unlike other frameworks that might convert UI elements into the operating system's widgets, Flutter does all the UI rendering itself.

This means Flutter needs a way to communicate with the host operating system to display its content, process user inputs, and manage app states. That's where platform embedding comes into play.

The platform embedder is essentially a bridge between Flutter and the native OS. It's responsible for initializing the Flutter engine, which runs your app, and creating a window or a texture where Flutter can draw its UI. This setup allows your Flutter app to run on Android, iOS, Windows, macOS, and Linux.

How Does It Work on Different Platforms?

Android and iOS

On Android, Flutter typically runs inside an Activity as a FlutterView. This FlutterView is where your Flutter UI is rendered. It can work as a view or a texture, based on your app's needs. For iOS, Flutter uses a UIViewController to integrate with the system. Both platforms use their respective APIs to handle app lifecycle events, input gestures, and other system services.

Desktop (Windows, macOS, Linux)

For desktop platforms, Flutter integrates differently. On Windows, it's hosted in a traditional Win32 application, with content rendered using ANGLE to translate OpenGL calls to DirectX. macOS uses an NSViewController for integration, while Linux details can vary based on the specific setup.

Custom Platform Embedders

One of the powerful features of Flutter is the ability to create custom platform embedders (checkout). This means if the default embedders don't meet your needs, you can build your own. Examples include creating an embedder for a Raspberry Pi or for systems that support VNC-style remote sessions.

Key Takeaways

  • Platform embedding in Flutter is how the framework communicates with the host operating system to display your app and handle its lifecycle.

  • Flutter comes with platform embedders for major operating systems, including Android, iOS, Windows, macOS, and Linux.

  • You can also create custom platform embedders to fit your specific requirements, offering great flexibility for developers.

Last updated