Irbisa · Cheatsheet
Add-to-App & Native Integration
FlutterEngine, multiple engines, embedding Flutter in an existing iOS or Android app, Pigeon, plugin vs FFI, size and startup
What is add-to-app, and how is a Flutter module created with
flutter create -t moduledifferent from a Flutter app?What is the difference between a
FlutterEngineand theFlutterActivityorFlutterViewControllerthat shows it?How do you add a Flutter module to an existing iOS app: SwiftPM, CocoaPods or prebuilt frameworks?
# in the Flutter module: generates build/ios/SwiftPackages/, add it to Xcode as a local packageflutter build swift-package --platform ios # build settings of the host targetFLUTTER_SWIFT_PACKAGE_OUTPUT = $(SRCROOT)/../my_flutter/build/ios/SwiftPackagesFLUTTER_APPLICATION_PATH = $(SRCROOT)/../my_flutter # optional: Xcode rebuilds Dart…How do you add a Flutter module to an existing Android app (as a source dependency or as AARs), and what does each cost?
// settings.gradle.kts, option 1: source dependency (every host build compiles Dart)apply(from = File(settingsDir.parentFile, "my_flutter/.android/include_flutter.groovy"))// app/build.gradle.kts: implementation(project(":flutter")) // settings.gradle.kts, option 2: AARs from `flutter build aar`dependencyResolutionManagement {…When do you embed Flutter on Android as a
FlutterActivity, aFlutterFragmentor a bareFlutterView?class HostActivity : FragmentActivity() { private var flutterFragment: FlutterFragment? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.host)…Who registers plugins when you create a
FlutterEngineyourself, and which plugins break in add-to-app?import Flutterimport FlutterPluginRegistrant @mainfinal class AppDelegate: UIResponder, UIApplicationDelegate, @preconcurrency FlutterAppLifeCycleProvider { private let lifecycle = FlutterPluginAppLifeCycleDelegate()…How does the native host tell the Flutter module which screen to open and with what data, on the first start and on later visits?
// lib/main.dart of the module: the host runs main unless it names another entrypointvoid main() => runApp(const ShopApp()); // kept by the AOT compiler even though no Dart code calls it@pragma('vm:entry-point')void settingsMain() => runApp(const SettingsApp());…Find the bug: after the cart moved into the app as a Flutter module, this code locks the session every time the user goes back to a native screen.
class SessionGuard with WidgetsBindingObserver { SessionGuard(this.auth) { WidgetsBinding.instance.addObserver(this); } final AuthService auth; @override void didChangeAppLifecycleState(AppLifecycleState state) { // the user left the app: ask for Face ID when they come back if (state == AppLifecycleState.paused) auth.lock(); }}Find the bug: every time the user opens Profile there is a blank pause, and the Flutter screen has forgotten everything from the last visit.
@MainActorfinal class ProfileCoordinator { func showProfile(userId: String, from host: UIViewController) { let engine = FlutterEngine(name: "profile") engine.run(withEntrypoint: nil, initialRoute: "/profile/\(userId)") GeneratedPluginRegistrant.register(with: engine) let flutterVC = FlutterViewController(engine: engine, nibName: nil, bundle: nil) flutterVC.modalPresentationStyle = .fullScreen host.present(flutterVC, animated: true) }}How do you debug and hot reload the Flutter part when the app is launched from Xcode or Android Studio as a native app?
Your app shows Flutter in several places at once: a tab, a card, a full-screen flow. Why use
FlutterEngineGroup, and what can those engines share?class App : Application() { lateinit var engines: FlutterEngineGroup override fun onCreate() { super.onCreate() engines = FlutterEngineGroup(this)…A user goes native → Flutter → native → Flutter. Who owns navigation and the Back gesture across that boundary?
How do you design the API between a native host and a Flutter module so two teams can change it safely?
The host already ships a C++ core and a Kotlin/Swift SDK. How should the Flutter module call each: Pigeon,
dart:ffi,ffigenorjnigen?import 'dart:ffi';import 'dart:io'; // The host already ships the C++ core: Android packages libcore.so,// iOS links it statically into the app binary.final DynamicLibrary _core = Platform.isIOS…What does adding a Flutter module cost the host app in download size and start-up time, and how do you keep that cost down?
class App : Application() { override fun onCreate() { super.onCreate() // cheap: loads libflutter.so and extracts assets on a background thread FlutterInjector.instance().flutterLoader().startInitialization(this)…You are asked to migrate a large native app to Flutter screen by screen. How would you plan the add-to-app rollout?