Skip to content
tezvyn:
Menu

Platform Views: Embedding Native UI in Flutter

Source: docs.flutter.devMediumHow cards are made

Platform Views cut a hole in your Flutter UI to show a native component. Use them to embed UI that can't be rebuilt in Dart, like Google Maps or a native WebView. Be warned: they are resource-heavy and can hurt performance if overused.

Why it exists

Flutter renders its own UI pixels, which is great for cross-platform consistency. However, sometimes you need to use a native component that doesn't have a Dart equivalent, such as a platform's built-in map view, a specialized ad SDK, or a complex, proprietary UI control you can't afford to rewrite. Platform Views were created to bridge this gap.

The mental model

Imagine your Flutter app is a painting on a canvas. A Platform View is like cutting a precise hole in that canvas and placing a small, live television screen behind it. The TV screen (the native view) plays its own content, independent of the painting, but it's perfectly framed by the hole you cut. You can interact with the TV, and Flutter manages its size and position on the canvas.

How it works

Flutter uses two main strategies. On Android, the default is "Hybrid Composition," which uses a standard Android View and coordinates its placement with the Flutter UI. On iOS, it uses a similar approach with UIView. For more complex cases or older Android versions, "Virtual Display" mode renders the native view to an off-screen texture that Flutter then draws into its scene. This texture-based approach has more performance overhead. Flutter manages passing touch events to the native view and compositing it into the final frame.

When to use it

Use Platform Views when you absolutely must integrate a native UI component. This is common for three scenarios: first, embedding map views (like Google Maps or Apple Maps); second, using a specific WebView implementation; third, integrating a third-party native SDK that provides its own UI (e.g., a payment processor or video player).

When not to use it

Avoid Platform Views for UI that can be built with Flutter widgets. They are a performance-heavy "escape hatch," not a standard tool. Each view adds memory and rendering overhead, can complicate input handling (like keyboard focus), and may not participate in Flutter's animations and transformations as smoothly as pure Dart widgets. If a good Dart package exists for your use case, prefer it.

One canonical example

A common use case is embedding Google Maps. The google_maps_flutter plugin uses a Platform View. When you add a GoogleMap widget to your app, the plugin instantiates a native MapView on Android or MKMapView on iOS behind the scenes and embeds it in your Flutter layout, allowing you to interact with a fully-featured native map from your Dart code.

Interview question

What is the main reason to incorporate a Platform View into a Flutter application?

  • a.To embed a native UI component that lacks a Dart equivalent.Correct
  • b.To facilitate direct communication with native device hardware APIs.
  • c.To allow Flutter widgets to seamlessly adopt native platform styling.
  • d.To improve the rendering performance of custom Flutter widgets.
Why?

The card explicitly states Platform Views were created to "use a native component that doesn't have a Dart equivalent," such as map views or native WebViews. Option D is incorrect because Platform Views are performance-heavy, not performance enhancers for Flutter widgets. Option B describes the function of platform channels, not Platform Views, which are specifically for embedding native UI.

Just read this? Test yourself on what you have been reading.

Read the original → docs.flutter.dev

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.

See open roles