Skip to content

Commit a48c8da

Browse files
mboetgersfshaza2
andauthored
[3.41] Add Android Content Sizing Documentation (#13000)
Add Android Content Sizing Documentation. This PR assumes flutter/samples#2787 has landed. ## Presubmit checklist - [X] If you are unwilling, or unable, to sign the CLA, even for a _tiny_, one-word PR, please file an issue instead of a PR. - [X] If this PR is not meant to land until a future stable release, mark it as draft with an explanation. - [X] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style)—for example, it doesn't use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first-person pronouns). - [X] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. --------- Co-authored-by: Shams Zakhour <44418985+sfshaza2@users.noreply.github.com>
1 parent 38aa0c9 commit a48c8da

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

src/content/add-to-app/android/add-flutter-view.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,63 @@ demo class or in the
9191
[`FlutterActivityAndFragmentDelegate`](https://cs.opensource.google/flutter/engine/+/main:shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java)
9292
to ensure a correct functioning of other features such as clipboards,
9393
system UI overlay, plugins, and so on.
94+
95+
## Content-sized views
96+
97+
Usually, a [`FlutterView`]({{site.api}}/javadoc/io/flutter/embedding/android/FlutterView.html)
98+
needs fixed dimensions either through it's own dimensions or by matching a
99+
parent's dimensions. This can be seen in the [sample project]({{site.repo.samples}}/tree/main/add_to_app/android_view/android_view).
100+
However, it's now possible to allow `FlutterView` to size itself
101+
based on its content. By using, `content_wrap` for either the height
102+
or the width a `FlutterView` can size itself, as shown in the [content sized sample project]({{site.repo.samples}}/tree/main/add_to_app/android_view/content_sizing_android_view).
103+
104+
* To _enable_ Content-sized view when deploying your app,
105+
add the following setting to your project's
106+
`AndroidManifest.xml` file under the `<application>` tag:
107+
108+
```xml
109+
<meta-data
110+
android:name="io.flutter.embedding.android.EnableContentSizing"
111+
android:value="true" />
112+
```
113+
114+
### Restrictions
115+
116+
Since content-sized Flutter views require your Flutter app to be able to size itself,
117+
some widgets are not supported.
118+
119+
* A widget with unbounded size, like a `ListView`.
120+
* A widget that defers to its child for the size, like `LayoutBuilder`.
121+
122+
In practice, this means that quite a few common widgets are not supported,
123+
such as `ScaffoldBuilder`, `CupertinoTimerPicker`,
124+
or any widget that internally relies on a `LayoutBuilder`.
125+
When in doubt, you can use an `UnconstrainedBox` to test the usability of
126+
a widget for a content-sized view, as shown in the following example:
127+
128+
```dart
129+
import 'package:flutter/material.dart';
130+
131+
void main() => runApp(MyApp());
132+
133+
class MyApp extends StatelessWidget {
134+
@override
135+
Widget build(BuildContext context)
136+
=> MaterialApp(home: MyPage());
137+
}
138+
139+
class MyPage extends StatelessWidget {
140+
@override
141+
Widget build(BuildContext context) {
142+
return Scaffold(
143+
body: UnconstrainedBox(
144+
// TODO: Edit this line to check if a widget
145+
// can cause problems with content-sized views.
146+
child: Text('This works!'),
147+
// child: Column(children: [Column(children: [Expanded(child: Text('This blows up!'))])]),
148+
// child: ListView(children: [Text('This blows up!')]),
149+
)
150+
);
151+
}
152+
}
153+
```

0 commit comments

Comments
 (0)