-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Extend InputDecoration with prefix/suffix padding #19514
Extend InputDecoration with prefix/suffix padding #19514
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
This looks reasonable however It might be simpler to just expose prefix/suffix widgets as an alternative to prefixText and suffixText. The input decorator internals (see _RenderDecorator etc) are already set up that way. Supporting widget values is more consistent with Flutter's overall approach and it scales better than adding more properties like this. |
I'm afraid this issue has come up frequently; just hasn't been addressed yet. See also: |
Yep thought about this too, but if we remove prefixText and suffixText it might break some apps. What about exposing prefix and suffix too and only use prefixText and suffixText when no prefix/suffix is set? |
What about replacing prefixIcon, prefixText, ... with only prefix? Having so many options for specifying the prefix is confusing. |
Sound good. We should assert if both attributes, say prefix and prefixText, are specified. We can't get rid of prefixText and suffixText because backwards compatibility. Likewise, we can't replace prefixText and prefixIcon with just prefix. Ofcourse if we were starting over, that would make sense. |
Alright, will work on it tomorrow |
Ok replaced the padding parameters with prefix and suffix.
Yep, when both prefix and prefixText is declared an assertion error is thrown. Same applies for suffix and suffixText. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking pretty good. It will need tests.
final Widget prefix = decoration.prefixText == null ? null : | ||
new AnimatedOpacity( | ||
final Widget prefix = decoration.prefix == null && decoration.prefixText == null ? null | ||
: new AnimatedOpacity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2-space indentation got clobbered here and below.
@@ -1833,6 +1833,10 @@ class InputDecoration { | |||
/// no border is drawn. | |||
/// | |||
/// The [enabled] argument must not be null. | |||
/// | |||
/// Only [prefix] or [prefixText] can be declared. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only one of [prefix] and [prefixText] can be specified.
@@ -1833,6 +1833,10 @@ class InputDecoration { | |||
/// no border is drawn. | |||
/// | |||
/// The [enabled] argument must not be null. | |||
/// | |||
/// Only [prefix] or [prefixText] can be declared. | |||
/// Declaring both ends with an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally don't include statements like this in the docs.
final Widget prefix = decoration.prefixText == null ? null : | ||
new AnimatedOpacity( | ||
final Widget prefix = decoration.prefix == null && decoration.prefixText == null ? null | ||
: new AnimatedOpacity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to honor the prefix textStyle here. I'd suggest defining a trivial private widget like _AffixText that deals with suffix and prefix and their AnimatedOpacity:
new _AffixText(
text: prefixText,
chlid: prefix,
style: decoration.prefixStyle ?? hintStyle,
labelIsFloating: widget._labelIsFloating,
)
Where _AffixText
either builds a DefaultTextStyle that contains child
or a new Text widget with the specified style.
final Widget suffix = decoration.suffixText == null ? null : | ||
new AnimatedOpacity( | ||
final Widget suffix = decoration.suffix == null && decoration.suffixText == null ? null | ||
: new AnimatedOpacity( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use _AffixText here as well.
@@ -2258,34 +2291,40 @@ class InputDecoration { | |||
|
|||
@override | |||
int get hashCode { | |||
// split into multiple hashValues calls | |||
// because the hashValues function only takes up to 20 fields... | |||
return hashValues( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement can be left as it is - two calls to hashValues(). Just move a few of the parameters to the second call up into the first parameter list.
@@ -2035,6 +2046,14 @@ class InputDecoration { | |||
/// See [Icon], [ImageIcon]. | |||
final Widget prefixIcon; | |||
|
|||
/// Optional widget to place on the line before the input. | |||
/// Can be for example used to add some padding to the [prefixText] or to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be for example => Can be
@@ -2074,6 +2093,14 @@ class InputDecoration { | |||
/// See [Icon], [ImageIcon]. | |||
final Widget suffixIcon; | |||
|
|||
/// Optional widget to place on the line after the input. | |||
/// Can be for example used to add some padding to the [suffixText] or to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be for example => Can be
@@ -2035,6 +2046,14 @@ class InputDecoration { | |||
/// See [Icon], [ImageIcon]. | |||
final Widget prefixIcon; | |||
|
|||
/// Optional widget to place on the line before the input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth explaining that the prefix widget's baseline will be lined up with the input baseline.
@@ -2074,6 +2093,14 @@ class InputDecoration { | |||
/// See [Icon], [ImageIcon]. | |||
final Widget suffixIcon; | |||
|
|||
/// Optional widget to place on the line after the input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth explaining that the suffix widget's baseline will be lined up with the input's baseline.
Thanks! I really appreciate your advice. I am struggling a bit with my english but i will try my best in future commits 😅 |
I am not that familiar with testing flutter widgets but I will try it. |
new _AffixText( | ||
labelIsFloating: widget._labelIsFloating, | ||
text: decoration.prefixText, | ||
style: decoration.prefixStyle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style shoudl be decoration.prefixStyle ?? hintStyle
, as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed it
new _AffixText( | ||
labelIsFloating: widget._labelIsFloating, | ||
text: decoration.suffixText, | ||
style: decoration.suffixStyle, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style should be decoration.suffixStyle ?? hintStyle
, as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ups fixed it
Is it ok if i rebase and squash? |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test looks good. I will land this PR once you've finished with the squash/rebase.
LGTM
Here we go |
Can you fix up the analyzer errors? Const is no longer needed in subexpressions of a const expression. |
Yep all checks pass :D |
Allows to make some space between the suffix/prefix text and the text entered into the text field.
(fixes #19460 @HansMuller)