-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Adds prefix and suffix support to TextField, per Material Design spec. #10675
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
Conversation
| this.prefixText, | ||
| this.prefixStyle, | ||
| this.suffixText, | ||
| this.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.
nit: trailing comma
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.
|
|
||
| /// Optional text prefix to place on the line before the input. | ||
| /// | ||
| /// Uses the [prefixStyle]. Uses [hintStyle] if [prefixStyle] isn't |
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.
nitty nit nit: here and below, only one space after a period
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.
LOL! OK. I blame my fingers.
| String prefixText, | ||
| TextStyle prefixStyle, | ||
| String suffixText, | ||
| TextStyle 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.
nit: trailing comma
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
| (decoration?.prefixText != null || decoration?.suffixText != null)) { | ||
| final List<Widget> rowContents = <Widget>[]; | ||
| if (decoration.prefixText != null) { | ||
| rowContents.add(new Text(decoration.prefixText, |
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.
nit: line break before and after the new Text( and before the matching )s
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.
Done.
So, what's the policy on using dartfmt on Flutter code? This is the kind of formatting that I just don't think about anymore because for all the other Dart code I write there is a presubmit that prevents non-dartfmt'ed code from being checked in. Of course, I'm afraid to run it here and change all kinds of other stuff.
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.
dartfmt doesn't implement Flutter style so we can't use it. We are looking into other options but don't currently have one.
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo describes Flutter style.
| } | ||
| rowContents.add(new Expanded(child: child)); | ||
| if (decoration.suffixText != null) { | ||
| rowContents.add(new Text(decoration.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.
ditto
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.
Done.
| expect(newPos.dy, lessThan(pos.dy)); | ||
| }); | ||
|
|
||
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.
nit: remove trailing spaces
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.
Done.
|
I'd rather we didn't have the changes to the This patch looks great! Thanks so much! |
gspencergoog
left a comment
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.
OK, I think I took care of everything. Thanks for the quick review!
| this.prefixText, | ||
| this.prefixStyle, | ||
| this.suffixText, | ||
| this.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.
Fixed.
| String prefixText, | ||
| TextStyle prefixStyle, | ||
| String suffixText, | ||
| TextStyle 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.
Fixed
| (decoration?.prefixText != null || decoration?.suffixText != null)) { | ||
| final List<Widget> rowContents = <Widget>[]; | ||
| if (decoration.prefixText != null) { | ||
| rowContents.add(new Text(decoration.prefixText, |
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.
Done.
So, what's the policy on using dartfmt on Flutter code? This is the kind of formatting that I just don't think about anymore because for all the other Dart code I write there is a presubmit that prevents non-dartfmt'ed code from being checked in. Of course, I'm afraid to run it here and change all kinds of other stuff.
| } | ||
| rowContents.add(new Expanded(child: child)); | ||
| if (decoration.suffixText != null) { | ||
| rowContents.add(new Text(decoration.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.
Done.
| expect(newPos.dy, lessThan(pos.dy)); | ||
| }); | ||
|
|
||
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.
Done.
|
Let me know if you'd like me to land this for you. |
|
Yes, please do: I don't have committer access. |
|
Landed, thanks! |
|
This slightly regressed the flutter_gallery__memory_nav diff_total_kb and flutter_gallery__memory_nav end_total_kb benchmarks, but presumably that's because we're now allocating slightly more to run the relevant gallery tests. We went from around 135,023KB to around 137,148KB. |
|
How would this small change cause 2MB of memory usage regression? That seems odd. |
|
We have a 10MB variance on the complex_layout_scroll_perf__memory start_total_kb benchmark from run to run, so 2MB is not huge. Maybe this increased our memory usage by 1KB per frame and that pushed us into the next GC pool size or something. |
This PR implements the prefix and suffix portions of the Material Design spec for TextField. It also fixes #10559.
The new interface is on the InputDecoration, adding four fields: prefixText, suffixText, prefixStyle, suffixStyle, which supply the text and text style for each.
If there is a hint or label in the way (e.g. it's supposed to be drawn in the text field), then the prefix/suffix text won't appear, but otherwise it will. So, for instance, if you have just hint text, then the prefix/suffix won't appear until you enter something in the field, since the hint needs to be displayed until then. If you have no hint text, but a label, then the prefix/suffix will appear whenever the label isn't inside the field (i.e. whenever it's focused). If you have neither, then the prefix/suffix is there all the time.
I also updated the gallery and added tests.