Skip to content

Conversation

@gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Jun 13, 2017

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.

this.prefixText,
this.prefixStyle,
this.suffixText,
this.suffixStyle
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: trailing comma

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: trailing comma

Copy link
Contributor Author

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,
Copy link
Contributor

@Hixie Hixie Jun 13, 2017

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

Copy link
Contributor Author

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.

Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

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));
});

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove trailing spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Hixie
Copy link
Contributor

Hixie commented Jun 13, 2017

I'd rather we didn't have the changes to the .iml files (in fact I'd rather we didn't have them at all, but that's a problem for another PR!).

This patch looks great! Thanks so much!

Copy link
Contributor Author

@gspencergoog gspencergoog left a 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
Copy link
Contributor Author

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
Copy link
Contributor Author

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,
Copy link
Contributor Author

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,
Copy link
Contributor Author

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));
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@Hixie
Copy link
Contributor

Hixie commented Jun 14, 2017

LGTM

@Hixie
Copy link
Contributor

Hixie commented Jun 14, 2017

Let me know if you'd like me to land this for you.

@gspencergoog
Copy link
Contributor Author

Yes, please do: I don't have committer access.

@Hixie Hixie merged commit 9f344b6 into flutter:master Jun 14, 2017
@Hixie
Copy link
Contributor

Hixie commented Jun 14, 2017

Landed, thanks!

@Hixie
Copy link
Contributor

Hixie commented Jun 14, 2017

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.

@eseidelGoogle
Copy link
Contributor

How would this small change cause 2MB of memory usage regression? That seems odd.

@Hixie
Copy link
Contributor

Hixie commented Jun 14, 2017

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add prefix/suffix support to TextField

4 participants