-
Notifications
You must be signed in to change notification settings - Fork 1
Experimental: Add Flutter View
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.
Flutter can be added to an Android app as a single View
in an Activity
's View
hierarchy.
Before adding Flutter as a single View
, you should consider if it is possible to add Flutter as a Fragment
or an Activity
to reduce your development burden.
If you really need to add Flutter as a single View
then do the following.
Create and start a FlutterEngine
by following the appropriate instructions. See the FlutterEngine page
// Instantiate a new FlutterView.
FlutterView flutterView = new FlutterView(this);
// Add your FlutterView wherever you'd like. In this case we add
// the FlutterView to a FrameLayout.
FrameLayout frameLayout = findViewById(R.id.framelayout);
frameLayout.addView(flutterView);
Your FlutterView
will not render anything at this point because it is not backed by any particular Flutter app.
flutterView.attachToFlutterEngine(flutterEngine);
At this point you should see your Flutter UI rendering to your FlutterView
, and touch interaction should work.
TODO(mattcarroll): update this info about the platform plugin
Fundamental communication between the Android platform and your Flutter app takes place over a MethodChannel
with the name "flutter/platform"
. For example, Android's onPostResume()
call must be forwarded over the flutterPlatformChannel
with the message "AppLifecycleState.resumed"
.
platformPlugin = new PlatformPlugin(activity);
MethodChannel flutterPlatformChannel = new MethodChannel(
flutterEngine.getDartExecutor(),
"flutter/platform",
JSONMethodCodec.INSTANCE
);
flutterPlatformChannel.setMethodCallHandler(platformPlugin);
TODO(mattcarroll)
TODO(mattcarroll)
TODO(mattcarroll)
- Home of the Wiki
- Roadmap
- API Reference (stable)
- API Reference (master)
- Glossary
- Contributor Guide
- Chat on Discord
- Code of Conduct
- Issue triage reports
- Our Values
- Tree hygiene
- Issue hygiene and Triage
- Style guide for Flutter repo
- Project teams
- Contributor access
- What should I work on?
- Running and writing tests
- Release process
- Rolling Dart
- Manual Engine Roll with Breaking Commits
- Updating Material Design Fonts & Icons
- Postmortems
- Setting up the Framework development environment
- The Framework architecture
- The flutter tool
- API Docs code block generation
- Running examples
- Using the Dart analyzer
- The flutter run variants
- Test coverage for package:flutter
- Writing a golden-file test for package:flutter
- Setting up the Engine development environment
- Compiling the engine
- Debugging the engine
- Using Sanitizers with the Flutter Engine
- Testing the engine
- The Engine architecture
- Flutter's modes
- Engine disk footprint
- Comparing AOT Snapshot Sizes
- Custom Flutter engine embedders
- Custom Flutter Engine Embedding in AOT Mode
- Flutter engine operation in AOT Mode
- Engine-specific Service Protocol extensions
- Crashes
- Supporting legacy platforms
- Metal on iOS FAQ
- Engine Clang Tidy Linter
- Why we have a separate engine repo
- Reduce Flutter engine size with MLGO
- Setting up the Plugins development environment
- Setting up the Packages development environment
- Plugins and Packages repository structure
- Plugin Tests
- Contributing to Plugins and Packages
- Releasing a Plugin or Package
- Unexpected Plugins and Packages failures