flutter/docs/wiki_archive/Experimental-Add-Flutter-View.md
Kate Lovett 1fbcbb73a0
[wiki migration] Leftover wiki pages and links (#148989)
This is waiting on 
- https://github.com/flutter/flutter/pull/148777
- https://github.com/flutter/flutter/pull/148790

After this PR lands, there will likely be 1-2 more clean up PRs, after which the migration will be done!

---

This moves the remaining wiki pages as planned in [flutter.dev/go/migrate-flutter-wiki-spreadsheet](https://docs.google.com/spreadsheets/d/1x65189ZBdNiLRygpUYoU08pwvXD4M-Z157c6pm8deGI/edit?usp=sharing) 

It also adds the team labels to the label bot for future PRs.

Changes to the content were only updating cross links, or links to refer to the main branch rather than master.
Remaining links to the wiki will be updated once all other pages have finished moving, they still work in the meantime.

Part of https://github.com/flutter/flutter/issues/145009
2024-05-28 15:12:10 +00:00

67 lines
2.3 KiB
Markdown

_**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.**_
# Add a Flutter View
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` to reduce your development burden.
* [How to use a `FlutterFragment`](Experimental-Add-Flutter-Fragment-ViewPager.md)
If you really need to add Flutter as a single `View` then do the following.
## How to use FlutterView
### Create and start a FlutterEngine
Create and start a `FlutterEngine` by following the appropriate instructions. See the [FlutterEngine page](Experimental-Reuse-FlutterEngine-across-screens.md)
### Create a FlutterView and add to layout
```java
// 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.
### Attach your FlutterView to your FlutterEngine
```java
flutterView.attachToFlutterEngine(flutterEngine);
```
At this point you should see your Flutter UI rendering to your `FlutterView`, and touch interaction should work.
### Create and configure platform plugin
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"`.
```java
platformPlugin = new PlatformPlugin(activity);
MethodChannel flutterPlatformChannel = new MethodChannel(
flutterEngine.getDartExecutor(),
"flutter/platform",
JSONMethodCodec.INSTANCE
);
flutterPlatformChannel.setMethodCallHandler(platformPlugin);
```
### Add accessibility support
TODO(mattcarroll)
### Add support for plugins
TODO(mattcarroll)
### Handling orientation change
TODO(mattcarroll)