-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
This adds multiline text widget support. #12120
Conversation
@@ -56,6 +63,9 @@ enum TextInputType { | |||
enum TextInputAction { | |||
/// Complete the text input operation. | |||
done, | |||
/// The action to take when the enter button is pressed in a multi-line |
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: missing newline
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.
@@ -93,13 +106,17 @@ class TextInputConfiguration { | |||
/// What text to display in the text input control's action button. | |||
final String actionLabel; | |||
|
|||
/// What kind of action to request for the action button on the IME. | |||
final TextInputAction inputAction; | |||
|
|||
/// Returns a representation of this object as a JSON object. | |||
Map<String, dynamic> toJSON() { |
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 isn't a JSON object, it's a Map...
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.
(no need to fix this unless you want to go on a rampage and fix all of them)
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.
I think I'll leave that for another rampage. But I agree with you.
@@ -276,6 +293,8 @@ class TextInputConnection { | |||
|
|||
TextInputAction _toTextInputAction(String action) { | |||
switch (action) { | |||
case 'TextInputAction.newline': | |||
return TextInputAction.newline; | |||
case 'TextInputAction.done': | |||
return TextInputAction.done; |
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 should keep the switch and the enum definition in the same order unless the order matters
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.
/// the number of lines. By default, it is 1, meaning this is a single-line | ||
/// text field. If it is not null, it must be greater than zero. | ||
/// the number of lines. By default, it is one, meaning this is a single-line | ||
/// text field. [maxLines] must not be set to zero. |
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.
According to your change here, it's now allowed to be negative, which I doubt is what you intended.
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.
Yikes. Yes, you're correct. Fixed.
/// The [controller], [focusNode], [style], [cursorColor], and [textAlign] | ||
/// arguments must not be null. | ||
/// If [maxLines] is not one, then [keyboardType] will be ignored, and the | ||
/// keyboard type [TextInputType.multiline] will be used. |
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.
why?
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.
I think it'd be cleaner if the default for keyboardType depended on maxLines, but if it was set, it was honoured regardless.
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.
+1. I can't imagine much use for a multi-line phone number, but it does seem fair that if someone adds a multi-line text field and request a phone keyboard, that we give them one.
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'll honor the setting then. Each of our existing keyboard types is for single-line input, so it didn't seem to make sense for multiline fields to use a single-line keyboard, but I guess they should get what they ask for.
Note that if I do it this way, then it won't assert if they pass an explicit null for keyboardType, it'll just use the default value (since I have to use null to tell if we are in a default state or not).
@@ -194,7 +199,7 @@ class EditableText extends StatefulWidget { | |||
/// Defaults to false. | |||
final bool obscureText; | |||
|
|||
/// Whether to enable autocorrection. | |||
/// Whether to enable auto-correction. |
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.
Wikipedia says "autocorrection" is correct.
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.
Reverted.
inputAction: widget.keyboardType == TextInputType.multiline | ||
? TextInputAction.newline | ||
: TextInputAction.done | ||
)) |
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 formatting is off somehow here. There's two closing parens on the same line, but I don't see any lines with two opening parens.
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 fixed it.
@@ -28,6 +28,9 @@ class TestTextInput { | |||
|
|||
int _client = 0; | |||
|
|||
/// Arguments supplied to setCient. |
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.
typo?
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.
/// Requests the default platform keyboard, but accepts newlines when the | ||
/// enter key is pressed. This is the input type used for all multi-line text | ||
/// fields. | ||
multiline, |
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.
Would multilineText
be better, or just more pedantic?
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.
I think it would be redundant. I like multiline because we're already talking about "TextInputType", so it's already clear that it's text.
@@ -56,6 +63,9 @@ enum TextInputType { | |||
enum TextInputAction { | |||
/// Complete the text input operation. | |||
done, | |||
/// The action to take when the enter button is pressed in a multi-line |
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: s/button/key/
also covers physical keyboards.
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.
Funny, I chose 'button' because I felt it covered both, whereas 'key' just covered physical keyboards. Mind if I keep it as 'button'?
controller: controller, | ||
focusNode: focusNode, | ||
style: textStyle, | ||
cursorColor: cursorColor))); |
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.
Here and below: trailing commas.
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
tester.firstWidget(find.byType(EditableText)); | ||
expect(editableText.maxLines, equals(1)); | ||
expect(editableText.obscureText, equals(false)); | ||
expect(editableText.autocorrect, equals(true)); |
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.
isFalse
, isTrue
.
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.
await tester.showKeyboard(find.byType(EditableText)); | ||
controller.text = 'test'; | ||
await tester.idle(); | ||
print(tester.testTextInput.editingState.toString()); |
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.
Delete this line.
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.
Whoops. Debug print snuck in.
print(tester.testTextInput.editingState.toString()); | ||
expect(tester.testTextInput.editingState['text'], equals('test')); | ||
expect(tester.testTextInput.setClientArgs['inputType'], | ||
equals('TextInputType.multiline')); |
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.
Fine to wrap up to prev line. Even though it's a little over 80, it reads a teensy bit better.
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, although I'm not really seeing an algorithm for the line wraps here...
await tester.showKeyboard(find.byType(EditableText)); | ||
controller.text = 'test'; | ||
await tester.idle(); | ||
print(tester.testTextInput.editingState.toString()); |
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.
Drop this line.
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.
Dropped all prints.
await tester.showKeyboard(find.byType(EditableText)); | ||
controller.text = 'test'; | ||
await tester.idle(); | ||
print(tester.testTextInput.editingState.toString()); |
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.
Drop this one too :)
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
await tester.showKeyboard(find.byType(EditableText)); | ||
controller.text = 'test'; | ||
await tester.idle(); | ||
print(tester.testTextInput.editingState.toString()); |
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.
And this one.
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.
Die print, die!
597f447
to
9c73630
Compare
This adds support for multi-line text widgets, making a new TextInputAction.newline enum, and supporting a new TextInputType.multiline enum value.
There are still some issues with cursor placement in multi-line input, but those may go away when we switch to a non-Blink text renderer.
Fixes #8028