text
stringlengths
1
474
it’s additionally responsible for compiling
the Dart source code into machine code during runtime.A single Dart runtime exists per application session on
Android and iOS.A one-time Dart VM start is done when constructing the
FlutterEngine for the first time on
Android and when running a Dart entrypoint
for the first time on iOS.At this point, your Dart code’s snapshot
is also loaded into memory from your application’s files.This is a generic process that also occurs if you used the
Dart SDK directly, without the Flutter engine.The Dart VM never shuts down after it’s started.<topic_end>
<topic_start>
Creating and running a Dart Isolate
After the Dart runtime is initialized,
the Flutter engine’s usage of the Dart
runtime is the next step.This is done by starting a Dart Isolate in the Dart runtime.
The isolate is Dart’s container for memory and threads.
A number of auxiliary threads on the host platform are
also created at this point to support the isolate, such
as a thread for offloading GPU handling and another for image decoding.One isolate exists per FlutterEngine instance, and multiple isolates
can be hosted by the same Dart VM.On Android, this happens when you call
DartExecutor.executeDartEntrypoint()
on a FlutterEngine instance.On iOS, this happens when you call runWithEntrypoint:
on a FlutterEngine.At this point, your Dart code’s selected entrypoint
(the main() function of your Dart library’s main.dart file,
by default) is executed. If you called the
Flutter function runApp() in your main() function,
then your Flutter app or your library’s widget tree is also created
and built. If you need to prevent certain functionalities from executing
in your Flutter code, then the AppLifecycleState.detached
enum value indicates that the FlutterEngine isn’t attached
to any UI components such as a FlutterViewController
on iOS or a FlutterActivity on Android.<topic_end>
<topic_start>
Attaching a UI to the Flutter engine
A standard, full Flutter app moves to reach this state as
soon as the app is launched.In an add-to-app scenario,
this happens when you attach a FlutterEngine
to a UI component such as by calling startActivity()
with an Intent built using FlutterActivity.withCachedEngine()
on Android. Or, by presenting a FlutterViewController
initialized by using initWithEngine: nibName: bundle:
on iOS.This is also the case if a Flutter UI component was launched without
pre-warming a FlutterEngine such as with
FlutterActivity.createDefaultIntent() on Android,
or with FlutterViewController initWithProject: nibName: bundle:
on iOS. An implicit FlutterEngine is created in these cases.Behind the scene, both platform’s UI components provide the
FlutterEngine with a rendering surface such as a
Surface on Android or a CAEAGLLayer or CAMetalLayer
on iOS.At this point, the Layer tree generated by your Flutter
program, per frame, is converted into
OpenGL (or Vulkan or Metal) GPU instructions.<topic_end>
<topic_start>
Memory and latency
Showing a Flutter UI has a non-trivial latency cost.
This cost can be lessened by starting the Flutter engine
ahead of time.The most relevant choice for add-to-app scenarios is for you
to decide when to pre-load a FlutterEngine
(that is, to load the Flutter library, start the Dart VM,
and run entrypoint in an isolate), and what the memory and latency
cost is of that pre-warm. You also need to know how the pre-warm
affects the memory and latency cost of rendering a first Flutter
frame when the UI component is subsequently attached
to that FlutterEngine.As of Flutter v1.10.3, and testing on a low-end 2015 class device
in release-AOT mode, pre-warming the FlutterEngine costs:A Flutter UI can be attached during the pre-warm.
The remaining time is joined to the time-to-first-frame latency.Memory-wise, a cost sample (variable,
depending on the use case) could be:Latency-wise,
a cost sample (variable, depending on the use case) could be:The FlutterEngine should be pre-warmed late enough to delay the
memory consumption needed but early enough to avoid combining the
Flutter engine start-up time with the first frame latency of
showing Flutter.The exact timing depends on the app’s structure and heuristics.
An example would be to load the Flutter engine in the screen
before the screen is drawn by Flutter.Given an engine pre-warm, the first frame cost on UI attach is:Memory-wise, the cost is primarily the graphical memory buffer used for
rendering and is dependent on the screen size.Latency-wise, the cost is primarily waiting for the OS callback to provide
Flutter with a rendering surface and compiling the remaining shader programs
that are not pre-emptively predictable. This is a one-time cost.When the Flutter UI component is released, the UI-related memory is freed.
This doesn’t affect the Flutter state, which lives in the FlutterEngine
(unless the FlutterEngine is also released).For performance details on creating more than one FlutterEngine,
see multiple Flutters.
<topic_end>
<topic_start>Android Studio and IntelliJ
<topic_end>
<topic_start>
Installation and setup
Follow the Set up an editor
instructions to install the Dart and Flutter plugins.<topic_end>
<topic_start>
Updating the plugins
Updates to the plugins are shipped on a regular basis.
You should be prompted in the IDE when an update is available.To check for updates manually:<topic_end>
<topic_start>
Creating projects
You can create a new project in one of several ways.<topic_end>
<topic_start>
Creating a new project
Creating a new Flutter project from the Flutter starter app template
differs between Android Studio and IntelliJ.In Android Studio:In IntelliJ:<topic_end>
<topic_start>Setting the company domain
When creating a new app, some Flutter IDE plugins ask for an
organization name in reverse domain order,
something like com.example. Along with the name of the app,
this is used as the package name for Android, and the Bundle ID for iOS
when the app is released. If you think you might ever release this app,