将 Flutter 集成到现有应用
Add-to-app
It’s sometimes not practical to rewrite your entire application in Flutter allat once. For those situations, Flutter can be integrated into your existingapplication piecemeal, as a library or module. That module can thenbe imported into your Android or iOS (currently supported platforms) app torender a part of your app’s UI in Flutter. Or, just to run shared Dart logic.
In a few steps, you can bring the productivity and the expressiveness ofFlutter into your own app.
As of Flutter v1.12, add-to-app is supported for the basic scenario ofintegrating one full-screen Flutter instance at a time per app. It currently hasthe following limitations:
- Running multiple Flutter instances or running in partial screen views may haveundefined behavior.
- Using Flutter in background mode is still a WIP.
- Packing a Flutter library into another sharable library or packing multipleFlutter libraries into an application isn’t supported.
Supported features
Add to Android applications
- Auto-build and import the Flutter module by adding a Flutter SDK hook toyour Gradle script.
- Build your Flutter module into a generic Android Archive (AAR)for integration into your own build system and for better Jetifier interoperabilitywith AndroidX.
- FlutterEngineAPI for starting and persisting your Flutter environment independently ofattaching a FlutterActivity/FlutterFragment etc.
- Android Studio Android/Flutter co-editing and module creation/import wizard.
- Java and Kotlin host apps are supported.
- Flutter modules can use Flutter plugins to interactwith the platform. Android plugins should be migrated to the V2 plugins APIsfor best add-to-app correctness. As of Flutter v1.12, most of the pluginsmaintained by the Flutter teamas well as FlutterFirehave been migrated.
- Support for Flutter debugging and stateful hot reload by using
flutter attach
from IDEs or the command line to connect to an app that contains Flutter.
Add to iOS applications
- Auto-build and import the Flutter module by adding a Flutter SDK hook toyour CocoaPods and to your Xcode build phase.
- Build your Flutter module into a generic iOS Frameworkfor integration into your own build system.
- FlutterEngine API forstarting and persisting your Flutter environment independently of attaching aFlutterViewController.
- Objective-C and Swift host apps supported.
- Flutter modules can use Flutter plugins to interactwith the platform.
- Support for Flutter debugging and stateful hot reload by using
flutter attach
from IDEs or the command line to connect to an app that contains Flutter.
See our add-to-app GitHub Samples repositoryfor sample projects in Android and iOS that import a Flutter module for UI.
Get started
To get started, see our project integration guide for
[
Android
]($c70456a9744d6632.md)[
iOS
]($35a880c74b765909.md)
API usage
After Flutter is integrated into your project, see our API usage guides for
[
Android
]($5c529d327e527a64.md)[
iOS
]($d7033b35cebe470c.md)