Skip to content

Document that TextField.decoration is merged with InputDecorationTheme - #191260

Closed
Treamz wants to merge 1 commit into
flutter:masterfrom
Treamz:docs-textfield-decoration-theme-merge
Closed

Treamz wants to merge 1 commit into
flutter:masterfrom
Treamz:docs-textfield-decoration-theme-merge

Conversation

@Treamz

@Treamz Treamz commented Aug 18, 2026

Copy link
Copy Markdown

TextField.decoration's dartdoc describes what the decoration draws, but never mentions that the value passed here is combined with the ambient InputDecorationTheme rather than replacing it.

TextField builds its effective decoration with InputDecoration.applyDefaults:

https://github.com/flutter/flutter/blob/7deb8a4d/packages/flutter/lib/src/material/text_field.dart#L1208-L1210

and applyDefaults only substitutes properties that are null on the incoming InputDecoration (including border: border ?? theme.border). So a theme-provided border survives an InputDecoration that simply omits one, which is surprising if you read the property docs alone — that confusion is what #159629 reports.

This adds a paragraph to the decoration property documenting the merge and pointing at the explicit opt-out (border: InputBorder.none).

This covers the documentation half of #159629. The issue also proposes a mergeWithTheme-style flag on InputDecoration; that is an API proposal and is deliberately left out of this PR, so the issue should stay open.

Documentation-only change; no behavior change and no new tests.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

TextField.decoration's dartdoc did not mention that the decoration passed
here is combined with the ambient InputDecorationTheme via
InputDecoration.applyDefaults, rather than replacing it. That makes it
non-obvious why, for example, a theme-provided border survives an
InputDecoration that simply omits one.

Document the merge and point at the explicit opt-out.

Addresses the documentation half of
flutter#159629
@github-actions

Copy link
Copy Markdown

This pull request contains changes to Material or Cupertino, which are currently frozen in this repository.

Changes should be made in material_ui and/or cupertino_ui in the flutter/packages repository.

Please refer to #188444 for instructions.

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design labels Aug 18, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation for the decoration property of TextField to clarify how it merges with the ambient InputDecorationTheme. Feedback was provided to correct an inaccurate reference to a non-existent InputDecorationTheme.of method, suggesting instead to refer directly to the ambient ThemeData.inputDecorationTheme.

Comment on lines +427 to +433
/// This decoration does not replace the ambient [InputDecorationTheme], it is
/// merged with it by [InputDecoration.applyDefaults]. Only the properties
/// that are left null here take their value from [InputDecorationTheme.of],
/// which in turn defaults to [ThemeData.inputDecorationTheme]. So, for
/// example, when the theme specifies a border, passing an [InputDecoration]
/// that leaves [InputDecoration.border] null does not remove that border;
/// pass `border: InputBorder.none` to opt out of it explicitly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is no InputDecorationTheme.of method in Flutter. The ambient input decoration theme is retrieved via Theme.of(context).inputDecorationTheme. It is clearer and more accurate to refer directly to the ambient [ThemeData.inputDecorationTheme].

  /// This decoration does not replace the ambient [InputDecorationTheme], it is
  /// merged with it by [InputDecoration.applyDefaults]. Only the properties
  /// that are left null here take their value from the ambient
  /// [ThemeData.inputDecorationTheme]. So, for example, when the theme specifies
  /// a border, passing an [InputDecoration] that leaves [InputDecoration.border]
  /// null does not remove that border; pass `border: InputBorder.none` to opt
  /// out of it explicitly.

@Treamz

Treamz commented Aug 18, 2026

Copy link
Copy Markdown
Author

Closing in favour of flutter/packages#12493 — as the code-freeze bot notes, Material changes now belong in material_ui in flutter/packages. Same doc change, plus the required version bump and CHANGELOG entry.

@Treamz Treamz closed this Aug 18, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Sep 29, 2026
…DecorationTheme (#12493)

`TextField.decoration`'s dartdoc describes what the decoration draws, but never mentions that the value passed here is *combined* with the ambient `InputDecorationTheme` rather than replacing it.

`TextField` builds its effective decoration with `InputDecoration.applyDefaults` (`packages/material_ui/lib/src/text_field.dart`), and `applyDefaults` only substitutes properties that are null on the incoming `InputDecoration` — including `border: border ?? theme.border` (`packages/material_ui/lib/src/input_decorator.dart`). So a theme-provided border survives an `InputDecoration` that simply omits one, which is surprising if you read the property docs alone. That confusion is what flutter/flutter#159629 reports.

This adds a paragraph to the `decoration` property documenting the merge and pointing at the explicit opt-out (`InputBorder.none`).

This covers the documentation half of flutter/flutter#159629. The issue also proposes a `mergeWithTheme`-style flag on `InputDecoration`; that is an API proposal and is deliberately left out of this PR, so the issue should stay open.

Originally opened against `flutter/flutter` as flutter/flutter#191260, and moved here after the code-freeze bot pointed out that Material changes now belong in `material_ui`.

*Documentation-only change; no behavior change and no new tests.*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems f: material design framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant