What runs in a bundle
What your Dart code can use in a bundle, what it sees at run time, and what works differently from a normal build.
A bundle is your app compiled from the same source as a normal Flutter build. There is no Flitz API to call and no annotation to add. Your app's Dart code and the Flutter framework run as bytecode, and everything native comes from the host: the Dart runtime, the engine, and your plugins. One bundle runs on Android and iOS hosts alike.
This page lists what works in a bundle, what does not, and what behaves differently. For what has to match between a host and a bundle before it runs, see Compatibility.
At a glance
| Feature | In a bundle |
|---|---|
| Your Dart code and every package's Dart code | Works. It runs in an interpreter, so it is slower (Performance). |
| Build mode | Release: kReleaseMode is true, asserts never run (Build mode). |
--dart-define, --dart-define-from-file | Work, passed to flitz publish. |
| Telling a bundle apart | const bool.fromEnvironment('flitz.bundle') (Detect a bundle). |
| Plugins: method and event channels | Work for every plugin the host ships (Plugins). |
dart:ffi | Works with native code the host ships. Callbacks only on ARM64 hosts (FFI). |
Isolates: compute, Isolate.run, Isolate.spawn | Work (Isolates). |
| Assets: images, fonts, shaders | Work, packaged as in a normal build. |
Calls through dynamic | Work. |
| Adding or changing native code | Not possible. Rebuild the host. |
| Hot reload, the debugger, DevTools | Not available (Debugging). |
Build mode
A bundle always runs as a release build of your app:
kReleaseModeistrue.kDebugModeandkProfileModearefalse.- Asserts never run.
- Code behind
if (kDebugMode)never runs. A debug menu, extra logging, or a test hook that your app shows only in debug builds is missing from a bundle.
The build mode is set when the bundle is compiled. Passing
--dart-define=dart.vm.product=… or dart.vm.profile=… to flitz publish
has no effect.
Detect a bundle
Every bundle is compiled with the define flitz.bundle set to true:
const isBundle = bool.fromEnvironment('flitz.bundle');It is true in every bundle and false in every other build of your app,
including the host. Use it for anything that should differ when your app runs
as a bundle, such as a debug menu for reviewers that a kDebugMode check would
hide. A --dart-define of flitz.bundle has no effect.
Compile-time defines
flitz publish takes --dart-define and --dart-define-from-file, both
repeatable, and compiles them into the bundle. Read them as in any Flutter
build, with String.fromEnvironment, bool.fromEnvironment, and
int.fromEnvironment. See flitz publish.
Values are compiled into the bundle, so anyone who can download it can read them. Do not pass a secret you would not put in a build of your app.
Platform APIs
The Dart platform libraries — dart:core, dart:async, dart:io, dart:ui,
dart:ffi, and the rest — come from the host. Your bundle uses the ones in the
Flitz SDK your project pins:
- A call to a platform API that the pinned SDK does not have fails
flitz publishon your machine, not on a device. Usually it is an API from a newer Flutter version. See CLI troubleshooting. - Calls through
dynamicwork, into your own code and into the platform libraries. Platform.isAndroid,Platform.isIOS, anddefaultTargetPlatformreport the device the bundle runs on. The same bundle runs on both platforms.
Plugins and platform channels
Plugins work in a bundle as in a normal build. Their Dart side is in the bundle and their native side is in the host. Method channels and event channels work, for every plugin the host was built with.
- The host must ship every package with native code that your app depends on. A bundle that needs one the host lacks is refused before it runs. See Native packages.
- On iOS, your app delegate must register plugins on the bundle's engine. See Plugin registration.
- On Android, the bundle runs in its own process, where SDKs that initialize through a ContentProvider, such as Firebase, are not set up. See Where the bundle runs.
- A bundle cannot add native code. A new or upgraded plugin's native side reaches the device only with a new host build.
FFI
Bundles call native code through dart:ffi, but only native code the host
ships. FFI packages with a native build hook count as native packages, so the
host depends on them too. A bundle carries no native library and cannot load
one of its own. See FFI on the Compatibility page.
Works:
Pointer,Struct,Union,Array,AbiSpecificIntegertypes such asIntPtrandSize.@Nativefunctions,Native.addressOf,DynamicLibrary.open,.process, and.executable,lookupFunction, andasFunction.NativeFinalizer, allocators, andpackage:ffiarenas.- Structs passed by pointer, and small structs returned by value.
Works on ARM64 hosts, Android and iOS: native code calling back into Dart, with
Pointer.fromFunction, NativeCallable.isolateLocal, and
NativeCallable.listener. The listener can be called from any thread. A
callback may throw and return its exceptionalReturn value, may make FFI
calls, and may take a struct by value. Callbacks need a host built with a
Flitz SDK at iteration 8 or newer (<flutter-version>+flz.8).
Where callbacks are unavailable, creating one throws an UnsupportedError:
Unsupported operation: This function should be handled on call site.It is an ordinary Dart exception, and the bundle keeps running. You get it:
- on an x86_64 Android emulator running the host's x86_64 build. An emulator image with ARM translation runs an arm64-only host, and callbacks work there.
- on a host built with an older Flitz SDK.
Isolates
compute, Isolate.run, and Isolate.spawn work. The new isolate runs your
bundle's code, interpreted like the rest of it.
Performance
Your app's Dart code and the framework's Dart layer run in an interpreter. The platform libraries, rendering, layout, text shaping, platform channels, and your plugins' native code stay compiled. Pure-Dart computation is roughly 10–50× slower than in a release build, while rendering stays fast. A bundle is right for reviewing UI and flows, not for profiling or benchmarking.
Debugging
A bundle runs in a release-mode host, so you cannot attach the debugger or
DevTools to it, and hot reload does not apply. Debug with flutter run on
your machine as usual. Publish a bundle when you want your team to see the
result on a real device.