diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 9c290aa26b..4401ffa579 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -71,9 +71,7 @@ class TextField extends StatefulWidget { /// /// The [maxLines] property can be set to null to remove the restriction on /// the number of lines. By default, it is one, meaning this is a single-line - /// text field. [maxLines] must not be zero. If [maxLines] is not one, then - /// [keyboardType] is ignored, and the [TextInputType.multiline] keyboard - /// type is used. + /// text field. [maxLines] must not be zero. /// /// The [maxLength] property is set to null by default, which means the /// number of characters allowed in the text field is not restricted. If @@ -89,8 +87,8 @@ class TextField extends StatefulWidget { /// characters may be entered, and the error counter and divider will /// switch to the [decoration.errorStyle] when the limit is exceeded. /// - /// The [keyboardType], [textAlign], [autofocus], [obscureText], and - /// [autocorrect] arguments must not be null. + /// The [textAlign], [autofocus], [obscureText], and [autocorrect] arguments + /// must not be null. /// /// See also: /// @@ -101,8 +99,8 @@ class TextField extends StatefulWidget { this.controller, this.focusNode, this.decoration = const InputDecoration(), - TextInputType keyboardType = TextInputType.text, - this.textInputAction = TextInputAction.done, + TextInputType keyboardType, + this.textInputAction, this.textCapitalization = TextCapitalization.none, this.style, this.textAlign = TextAlign.start, @@ -122,9 +120,7 @@ class TextField extends StatefulWidget { this.cursorColor, this.keyboardAppearance, this.scrollPadding = const EdgeInsets.all(20.0), - }) : assert(keyboardType != null), - assert(textInputAction != null), - assert(textAlign != null), + }) : assert(textAlign != null), assert(autofocus != null), assert(obscureText != null), assert(autocorrect != null), @@ -132,7 +128,7 @@ class TextField extends StatefulWidget { assert(scrollPadding != null), assert(maxLines == null || maxLines > 0), assert(maxLength == null || maxLength > 0), - keyboardType = maxLines == 1 ? keyboardType : TextInputType.multiline, + keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), super(key: key); /// Controls the text being edited. @@ -156,14 +152,14 @@ class TextField extends StatefulWidget { /// The type of keyboard to use for editing the text. /// - /// Defaults to [TextInputType.text]. Must not be null. If - /// [maxLines] is not one, then [keyboardType] is ignored, and the - /// [TextInputType.multiline] keyboard type is used. + /// Defaults to [TextInputType.text] if [maxLines] is one and + /// [TextInputType.multiline] otherwise. final TextInputType keyboardType; /// The type of action button to use for the keyboard. /// - /// Defaults to [TextInputAction.done]. Must not be null. + /// Defaults to [TextInputAction.newline] if [keyboardType] is + /// [TextInputType.multiline] and [TextInputAction.done] otherwise. final TextInputAction textInputAction; /// Configures how the platform keyboard will select an uppercase or diff --git a/packages/flutter/lib/src/material/text_form_field.dart b/packages/flutter/lib/src/material/text_form_field.dart index e4a12f7dfa..50c04d70ca 100644 --- a/packages/flutter/lib/src/material/text_form_field.dart +++ b/packages/flutter/lib/src/material/text_form_field.dart @@ -54,9 +54,9 @@ class TextFormField extends FormField { String initialValue, FocusNode focusNode, InputDecoration decoration = const InputDecoration(), - TextInputType keyboardType = TextInputType.text, + TextInputType keyboardType, TextCapitalization textCapitalization = TextCapitalization.none, - TextInputAction textInputAction = TextInputAction.done, + TextInputAction textInputAction, TextStyle style, TextAlign textAlign = TextAlign.start, bool autofocus = false, @@ -75,8 +75,6 @@ class TextFormField extends FormField { Brightness keyboardAppearance, EdgeInsets scrollPadding = const EdgeInsets.all(20.0), }) : assert(initialValue == null || controller == null), - assert(keyboardType != null), - assert(textInputAction != null), assert(textAlign != null), assert(autofocus != null), assert(obscureText != null), diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 365bc06102..8cc1edc900 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -201,7 +201,7 @@ class EditableText extends StatefulWidget { this.selectionColor, this.selectionControls, TextInputType keyboardType, - this.textInputAction = TextInputAction.done, + this.textInputAction, this.textCapitalization = TextCapitalization.none, this.onChanged, this.onEditingComplete, @@ -597,9 +597,10 @@ class EditableTextState extends State with AutomaticKeepAliveClien inputType: widget.keyboardType, obscureText: widget.obscureText, autocorrect: widget.autocorrect, - inputAction: widget.keyboardType == TextInputType.multiline + inputAction: widget.textInputAction ?? (widget.keyboardType == TextInputType.multiline ? TextInputAction.newline - : widget.textInputAction, + : TextInputAction.done + ), textCapitalization: widget.textCapitalization, ) )..setEditingState(localValue); @@ -1036,4 +1037,4 @@ class _Editable extends LeafRenderObjectWidget { ..cursorWidth = cursorWidth ..cursorRadius = cursorRadius; } -} \ No newline at end of file +} diff --git a/packages/flutter/test/widgets/editable_text_test.dart b/packages/flutter/test/widgets/editable_text_test.dart index ac241bd0c5..9ce3ed36bc 100644 --- a/packages/flutter/test/widgets/editable_text_test.dart +++ b/packages/flutter/test/widgets/editable_text_test.dart @@ -292,6 +292,65 @@ void main() { equals('TextInputAction.newline')); }); + testWidgets('Multiline keyboard with newline action is requested when maxLines = null', (WidgetTester tester) async { + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new FocusScope( + node: focusScopeNode, + autofocus: true, + child: new EditableText( + controller: controller, + focusNode: focusNode, + maxLines: null, + style: textStyle, + cursorColor: cursorColor, + ), + ), + ), + ); + + await tester.tap(find.byType(EditableText)); + await tester.showKeyboard(find.byType(EditableText)); + controller.text = 'test'; + await tester.idle(); + expect(tester.testTextInput.editingState['text'], equals('test')); + expect(tester.testTextInput.setClientArgs['inputType']['name'], + equals('TextInputType.multiline')); + expect(tester.testTextInput.setClientArgs['inputAction'], + equals('TextInputAction.newline')); + }); + + testWidgets('Text keyboard is requested when explicitly set and maxLines = null', (WidgetTester tester) async { + await tester.pumpWidget( + new Directionality( + textDirection: TextDirection.ltr, + child: new FocusScope( + node: focusScopeNode, + autofocus: true, + child: new EditableText( + controller: controller, + focusNode: focusNode, + maxLines: null, + keyboardType: TextInputType.text, + style: textStyle, + cursorColor: cursorColor, + ), + ), + ), + ); + + await tester.tap(find.byType(EditableText)); + await tester.showKeyboard(find.byType(EditableText)); + controller.text = 'test'; + await tester.idle(); + expect(tester.testTextInput.editingState['text'], equals('test')); + expect(tester.testTextInput.setClientArgs['inputType']['name'], + equals('TextInputType.text')); + expect(tester.testTextInput.setClientArgs['inputAction'], + equals('TextInputAction.done')); + }); + testWidgets( 'Correct keyboard is requested when set explicitly and maxLines > 1', (WidgetTester tester) async {