Proposal: Make InputDecorationTheme usage in components consistent #131666
Labels
a: quality
A truly polished experience
a: text input
Entering text in a text field or keyboard related problems
c: proposal
A detailed proposal for a change to Flutter
f: material design
flutter/packages/flutter/material repository.
framework
flutter/packages/flutter repository. See also f: labels.
P2
Important issues not at the top of the work list
team-design
Owned by Design Languages team
triaged-design
Triaged by Design Languages team
Is there an existing issue for this?
Use case
The usage of
InputDecorationTheme
in component themes varies widely between component themes. This makes using components that useInputDecoration
unpredictable and confusing.The
InputDecoration
is typically used byTextField
,TextFormField
andDropdownButtonFormField
but also by other newer components that have text input fields. Comparing these components we find diverging and conflicting behavior.Different and confusing behavior
We now have at least four different styles for how
InputDecoration
behaves viainputDecoratorTheme
in components.1.
SearchBar
- Not inherited, no configThe
SearchBar
removes all influence fromtheme.inputDecorationTheme
decorator and always does its own style. It did not use to remove all influences fromtheme.inputDecorationTheme
correctly, but its intention was to do so. It had to be fixed (in issue #126623) to do so, since some props fromtheme.inputDecorationTheme
leaked through when you customized it and this destroyed the intended design ofSearchBar
.To offer customization if/when needed, this version could easily be expanded to version 2 below.
2.
DropdownMenu
- Not inherited, can give ownDoes not use global default
theme.inputDecorationTheme
(issue #131213), but we can give it a custom style via its component themeDropdownMenuThemeData.inputDecorationTheme
. If we want the same one we used fortheme.inputDecorationTheme
, we need to explicitly assign it in its componentThemeData.dropdownMenuTheme.inputDecorationTheme
theme as well.This version is actually clear and simple to use. It uses its own default, unless otherwise defined, easy and clear.
3.
TimePickerDialog
- Partially inherited, partially own, can give own styleThe
TimePickerDialog
has its own default styleInputDecoration
, however, some properties that are null in the default style will get a few values from the overalltheme.inputDecorationTheme
, like e.g. hover color will seep through from globaltheme.inputDecorationTheme
.You can provide a custom style in
TimePickerThemeData.inputDecorationTheme
and it will do a typical null fall through using it:flutter/packages/flutter/lib/src/material/time_picker.dart
Line 2018 in de5b967
For some parts in the input decorations it also picks up and uses other widget and theme properties if an
timePickerTheme.inputDecorationTheme
has not been provided.If you use a custom
TimePickerThemeData.inputDecorationTheme
you must be aware of that you need to provide some internal style fixes for e.g.errorStyle
that the picker does internally to its default decorator, for things to look correct. You may also need to provide some override values for property values that will come from the global input decorator (like hover color) if yourTimePickerThemeData.inputDecorationTheme
had null values for them, because if it did, it falls back to defaults for them, that part is basically just decorator default behavior though, but it can be surprising.4.
DatePickerDialog
- Inherited, cannot override none null valuesThe
DatePickerDialog
is the newest member to get aDatePickerThemeData.inputDecorationTheme
via PR #128950, before this, it only inherited it fromtheme.inputDecorationTheme
.The implementation it uses is very divergent from all the above styles.
The
merge
implementation in theInputDatePickerFormField
is problematic, it only merges a property from thedatePickerTheme.inputDecorationTheme
style, if has no defined style intheme.inputDecorationTheme
, basically only if it is null there, so we do not get the style defined in a property fordatePickerTheme.inputDecorationTheme
if one is already defined intheme.inputDecorationTheme
.When using a very elaborate
theme.inputDecorationTheme
, that defines pretty much all properties it has, this is still then the only style we can get, despite the addition of the recentdatePickerTheme.inputDecorationTheme
. This is of course because of howmerge
works, where it only fills in none null fields ininputTheme
below, and if all the fields ininputTheme
are none null, the mergeddatePickerTheme.inputDecorationTheme
has no impact whatsoever on the desired style, so we cannot change it, regardless of the addition of thedatePickerTheme.inputDecorationTheme
.This code is from:
https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/input_date_picker_form_field.dart
flutter/packages/flutter/lib/src/material/input_date_picker_form_field.dart
Line 262 in de5b967
If the used merge was:
At least then we get
datePickerTheme.inputDecorationTheme
props where given, that are and back-filled with theinputTheme = theme.inputDecorationTheme
property values, which would be more in line with what is expected and be more useful.When you have already made a VERY custom
theme.inputDecorationTheme
then pretty much every property in it is no longer null, you can then not provide any other values viaDatePickerTheme.inputDecorationTheme
with current implementation. This not only makes this implementation very divergent compared to others styles, it is also a fairly pointless property.Proposal
Consider harmonizing the different behavior of how
InputDecoration
is inherited and used in component themes that are not pureTextField
input derivatives.Current diverging styles and behaviors are very difficult to predict and reason about. Plus one of them does not even provide the needed independent from
theme.inputDecorationTheme
styling capabilities.It feels like the simplest one, the
DropdownMenu
approach is the one that is the easiest to reason about and provides good and expected behavior.If a widget already depends on the inherited InputDecoratorTheme from ThemeData, to some degree, it can of course still do so, but it imo it is cleaner if that style is then just completely ignored if you give it an own
InputDecoratorTheme
as a part of its component theme or even as a widget property.This also fits well with how other properties generally work in components and component themes.
Used Flutter version for the study
Channel master, 3.13.0-15.0.pre.16
Flutter doctor
The text was updated successfully, but these errors were encountered: