Skip to content

Experimental: Launch Flutter with non main entrypoint

Matt Carroll edited this page Apr 8, 2019 · 2 revisions

Everything in this doc and linked from this doc is experimental. These details WILL change. Do not use these instructions or APIs in production code because we will break you.

Launch Flutter with non-main entrypoint

Typically, a Flutter app begins execution at the Dart method called main(), however this is not required. Developers can specify a different Dart entrypoint:


To use a FlutterActivity with a custom Dart entrypoint, do the following.

// Launches FlutterActivity and runs a Dart method called mySpecialScreen().
Intent defaultFlutter = new FlutterActivity.IntentBuilder()


To use a FlutterActivity with a custom Dart entrypoint, do the following.

// Create a FlutterFragment that runs a Dart method called mySpecialScreen().
FlutterFragment flutterFragment = new FlutterFragment.Builder()


To use a FlutterView with a custom Dart entrypoint, do the following.

// Configure your entrypoint.
DartExecutor.DartEntrypoint entrypoint = new DartExecutor.DartEntrypoint(  

// Create a new FlutterEngine to run your entrypoint.
FlutterEngine engine = new FlutterEngine();

// Connect your FlutterEngine to your FlutterView.

Avoid Tree Shaking in Release

When you build in release mode, your Dart code is tree-shaken. This means that the compiler removes any Dart code that it thinks you're not using. This includes your special entrypoints. To avoid crashing in release mode as a result of tree-shaking, be sure to place the following @pragma above each of your custom entrypoints.

void mySpecialScreen() {
  // implementation

Flutter Wiki


Framework repo

Engine repo


Experimental features

Release Notes

Clone this wiki locally
You can’t perform that action at this time.