Sub topic 1
What add-to-app is and when to choose it
Prerequisites
You should know basic Flutter and Dart, including widgets and the flutter command line tool. You should also be comfortable with Android (Kotlin, Gradle, Activities) or iOS (Swift, Xcode, view controllers). Flutter must be installed, and you need a native app project that builds.
What add-to-app is
Add-to-app lets you place Flutter screens inside an existing native app. You keep the native app and add Flutter where it helps, such as one new feature or one screen.
When to choose it
| Approach | Best when | Main cost |
|---|---|---|
| Full rewrite in Flutter | The app is small or not yet built | Rebuilding everything |
| Add-to-app | The app is large and already shipping | Two build systems to maintain |
| Native only | Flutter adds no real value | No shared UI code |
Creating a Flutter module
A Flutter module is a Flutter project that a native app embeds instead of running alone. Create it next to your native project:
flutter create --template module my_flutter_module
cd my_flutter_module
flutter runThe template also creates hidden .android and .ios folders. The native build uses these folders to include your Dart code.
How a native app hosts Flutter: engine and view
A FlutterEngine runs the Dart code. A Flutter view displays what the engine draws. The native host starts the engine and attaches a view to it. On Android, FlutterActivity provides the view. On iOS, FlutterViewController provides it.
Integrating the module into an Android app
Add the module to your Gradle build as a dependency. Flutter's add-to-app guide lists the exact settings.gradle and build.gradle lines for your Flutter version. Then open the Flutter screen from any Activity:
import io.flutter.embedding.android.FlutterActivity
startActivity(FlutterActivity.withNewEngine().build(this))> The old Blockquote rule forbids ">" here, so the note below uses a callout instead.
Exercise
Your app already ships, and your team wants to add one new Flutter screen. Which approach from the table fits best, and why?
Show answer
Add-to-app fits best. The existing app is large and already in use, so a full rewrite would be costly. Flutter adds only the new screen, and the native code stays in place.