Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding adaptation info for text fields #8913

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions src/resources/platform-adaptations.md
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,73 @@ Scaffold(
.toList(),
));
```
### Text fields

Since Android 12, the default UI of text fields follows the design
guidelines defined in [Material 3][m3-text-field] (M3).
On iOS, Apple's [Human Interface Guidelines][hig-text-field] (HIG) define
an equivalent component.

<div class="container">
<div class="row">
<div class="col-sm text-center">
<figure class="figure">
<img src="/assets/images/docs/platform-adaptations/m3-text-field.png"
class="figure-img img-fluid rounded" alt="Text Field in Material 3" />
<figcaption class="figure-caption">
Text Field in Material 3
</figcaption>
</figure>
</div>
<div class="col-sm">
<figure class="figure text-center">
<img src="/assets/images/docs/platform-adaptations/hig-text-field.png"
class="figure-img img-fluid rounded" alt="Text Field in Human Interface Guidelines" />
<figcaption class="figure-caption">
Text Field in HIG
</figcaption>
</figure>
</div>
</div>
</div>

Since text fields require user input,
their design should follow platform conventions.

To implement a platform-specific `TextField`
in Flutter, you can adapt the styling of the
Material `TextField`.

```dart
Widget _createAdaptiveTextField() {
final _border = OutlineInputBorder(
borderSide: BorderSide(color: CupertinoColors.lightBackgroundGray),
);

final iOSDecoration = InputDecoration(
border: _border,
enabledBorder: _border,
focusedBorder: _border,
filled: true,
fillColor: CupertinoColors.white,
hoverColor: CupertinoColors.white,
contentPadding: EdgeInsets.fromLTRB(10, 0, 0, 0),
);

return Platform.isIOS
? SizedBox(
height: 36.0,
child: TextField(
decoration: iOSDecoration,
),
)
: TextField();
}
```

To learn more about adapting text fields, check out
[the GitHub discussion on text fields][text-field-post].
You can leave feedback or ask questions in the discussion.

### Alert dialog

Expand Down Expand Up @@ -847,3 +913,6 @@ You can leave feedback or ask questions in the discussion.
[UI Component section]: {{site.api}}/resources/platform-adaptations/#ui-components
[mat-navbar]: https://m3.material.io/components/navigation-bar/overview
[hig-tabbar]: https://developer.apple.com/design/human-interface-guidelines/components/navigation-and-search/tab-bars/
[text-field-post]: {{site.repo.uxr}}/discussions/95
[m3-text-field]: https://m3.material.io/components/text-fields/overview
[hig-text-field]: https://developer.apple.com/design/human-interface-guidelines/text-fields