Skip to content

Commit

Permalink
Changing a note to a warning and changing master -> main (#11593)
Browse files Browse the repository at this point in the history
As it says. Also altered some formatting.

Fixes #11485
  • Loading branch information
sfshaza2 authored Jan 16, 2025
1 parent ee6eec4 commit 664ed7b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 38 deletions.
77 changes: 47 additions & 30 deletions src/content/add-to-app/android/add-flutter-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,57 @@ for some of the cells in a RecycleView list of cards as seen in the gif above.

## General approach

The general gist of the FlutterView-level integration is that you must recreate
the various interactions between your Activity, the [FlutterView]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
and the [FlutterEngine]({{site.api}}/javadoc/io/flutter/embedding/engine/FlutterEngine.html)
present in the [FlutterActivityAndFragmentDelegate](https://cs.opensource.google/flutter/engine/+/master:shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java)
in your own application's code. The connections made in the [FlutterActivityAndFragmentDelegate](https://cs.opensource.google/flutter/engine/+/master:shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java)
are done automatically when using a [FlutterActivity]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterActivity.html)
or a [FlutterFragment]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterFragment.html),
but since the [FlutterView]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
in this case is being added to an Activity or Fragment in your application,
you must recreate the connections manually. Otherwise, the [FlutterView]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
will not render anything or have other missing functionalities.

A sample [FlutterViewEngine]({{site.repo.samples}}/blob/main/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/FlutterViewEngine.kt)
The general gist of the FlutterView-level integration is that you
must recreate the various interactions between your Activity, the
[`FlutterView`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
and the
[`FlutterEngine`]({{site.api}}/javadoc/io/flutter/embedding/engine/FlutterEngine.html)
present in the [`FlutterActivityAndFragmentDelegate`](https://cs.opensource.google/flutter/engine/+/main:shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java)
in your own application's code.
The connections made in the
[`FlutterActivityAndFragmentDelegate`](https://cs.opensource.google/flutter/engine/+/main:shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java)
are done automatically when using a
[`FlutterActivity`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterActivity.html)
or a
[`FlutterFragment`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterFragment.html),
but since the [`FlutterView`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
in this case is being added to an `Activity` or `Fragment` in your application,
you must recreate the connections manually.
Otherwise, the [`FlutterView`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
won't render anything or have other missing functionalities.

A sample
[`FlutterViewEngine`]({{site.repo.samples}}/blob/main/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/FlutterViewEngine.kt)
class shows one such possible implementation of an application-specific
connection between an Activity, a [FlutterView]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
connection between an `Activity`, a
[`FlutterView`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
and a [FlutterEngine]({{site.api}}/javadoc/io/flutter/embedding/engine/FlutterEngine.html).

### APIs to implement

The absolute minimum implementation needed for Flutter to draw anything at all
is to:

- Call [attachToFlutterEngine]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html#attachToFlutterEngine-io.flutter.embedding.engine.FlutterEngine-) when the
[FlutterView]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
is added to a resumed Activity's view hierarchy and is visible; and
- Call [appIsResumed]({{site.api}}/javadoc/io/flutter/embedding/engine/systemchannels/LifecycleChannel.html#appIsResumed--) on the [FlutterEngine]({{site.api}}/javadoc/io/flutter/embedding/engine/FlutterEngine.html)'s
`lifecycleChannel` field when the Activity hosting the [FlutterView]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
The absolute minimum implementation needed for Flutter
to draw anything at all is to:

* Call [`attachToFlutterEngine`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html#attachToFlutterEngine-io.flutter.embedding.engine.FlutterEngine-)
when the
[`FlutterView`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
is added to a resumed `Activity`'s view hierarchy and is visible; and
* Call [`appIsResumed`]({{site.api}}/javadoc/io/flutter/embedding/engine/systemchannels/LifecycleChannel.html#appIsResumed--)
on the [`FlutterEngine`]({{site.api}}/javadoc/io/flutter/embedding/engine/FlutterEngine.html)'s
`lifecycleChannel` field when the `Activity` hosting the
[`FlutterView`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
is visible.

The reverse [detachFromFlutterEngine]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html#detachFromFlutterEngine--) and other lifecycle methods on the [LifecycleChannel]({{site.api}}/javadoc/io/flutter/embedding/engine/systemchannels/LifecycleChannel.html)
class must also be called to not leak resources when the FlutterView or Activity
is no longer visible.

In addition, see the remaining implementation in the [FlutterViewEngine]({{site.repo.samples}}/blob/main/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/FlutterViewEngine.kt)
demo class or in the [FlutterActivityAndFragmentDelegate](https://cs.opensource.google/flutter/engine/+/master:shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java)
to ensure a correct functioning of other features such as clipboards, system
UI overlay, plugins etc.
The reverse
[`detachFromFlutterEngine`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html#detachFromFlutterEngine--)
and other lifecycle methods on the
[`LifecycleChannel`]({{site.api}}/javadoc/io/flutter/embedding/engine/systemchannels/LifecycleChannel.html)
class must also be called to not leak resources when the
`FlutterView` or `Activity` is no longer visible.

In addition, see the remaining implementation in the
[`FlutterViewEngine`]({{site.repo.samples}}/blob/main/add_to_app/android_view/android_view/app/src/main/java/dev/flutter/example/androidView/FlutterViewEngine.kt)
demo class or in the
[`FlutterActivityAndFragmentDelegate`](https://cs.opensource.google/flutter/engine/+/main:shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java)
to ensure a correct functioning of other features such as clipboards,
system UI overlay, plugins, and so on.
10 changes: 6 additions & 4 deletions src/content/add-to-app/android/project-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,12 @@ val filePath = settingsDir.parentFile.toString() + "/flutter_module/.android/inc
apply(from = File(filePath))
```
:::note
The ability to invoke `include_flutter.groovy` from Kotlin code requires Flutter 3.27.
To determine your current Flutter version, run `flutter --version`. If it is not
at least version 3.27, consider changing to either the `master` or `beta` channels.
:::warning
The ability to invoke `include_flutter.groovy` from Kotlin code
requires Flutter 3.27.
To determine your current Flutter version,
run `flutter --version`. If it isn't at least version 3.27,
consider changing to either the `main` or `beta` channels.
:::

If you are using Groovy, apply the following changes:
Expand Down
2 changes: 1 addition & 1 deletion src/content/add-to-app/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Web limitations:
[`FlutterActivity`]: {{site.api}}/javadoc/io/flutter/embedding/android/FlutterActivity.html
[java-engine]: {{site.api}}/javadoc/io/flutter/embedding/engine/FlutterEngine.html
[ios-engine]: {{site.api}}/ios-embedder/interface_flutter_engine.html
[FlutterFire]: {{site.github}}/firebase/flutterfire/tree/master/packages
[FlutterFire]: {{site.github}}/firebase/flutterfire/tree/main/packages
[`FlutterFragment`]: {{site.api}}/javadoc/io/flutter/embedding/android/FlutterFragment.html
[`FlutterPlugin`]: {{site.api}}/javadoc/io/flutter/embedding/engine/plugins/FlutterPlugin.html
[`FlutterViewController`]: {{site.api}}/ios-embedder/interface_flutter_view_controller.html
Expand Down
4 changes: 2 additions & 2 deletions src/content/add-to-app/multiple-flutters.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ on both Android and iOS on [GitHub][].
[Issue 72009]: {{site.repo.flutter}}/issues/72009
[Pigeon]: {{site.pub}}/packages/pigeon
[platform channels]: /platform-integration/platform-channels
[Android API]: https://cs.opensource.google/flutter/engine/+/master:shell/platform/android/io/flutter/embedding/engine/FlutterEngineGroup.java
[iOS API]: https://cs.opensource.google/flutter/engine/+/master:shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h
[Android API]: https://cs.opensource.google/flutter/engine/+/main:shell/platform/android/io/flutter/embedding/engine/FlutterEngineGroup.java
[iOS API]: https://cs.opensource.google/flutter/engine/+/main:shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h
2 changes: 1 addition & 1 deletion src/content/add-to-app/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ For performance details on creating more than one `FlutterEngine`,
see [multiple Flutters][].

[android-engine]: {{site.api}}/javadoc/io/flutter/embedding/engine/FlutterEngine.html
[auxiliary threads]: {{site.repo.flutter}}/blob/master/docs/about/The-Engine-architecture.md#threading
[auxiliary threads]: {{site.repo.flutter}}/blob/main/docs/about/The-Engine-architecture.md#threading
[CAEAGLLayer]: {{site.apple-dev}}/documentation/quartzcore/caeagllayer
[CAMetalLayer]: {{site.apple-dev}}/documentation/quartzcore/cametallayer
[Dart `Isolate`]: {{site.dart.api}}/dart-isolate/Isolate-class.html
Expand Down

0 comments on commit 664ed7b

Please sign in to comment.