Unverified Commit 3ca6445c authored by matthew-carroll's avatar matthew-carroll Committed by GitHub

Added textInputAction parameter to TextFormField that forwards to TextField,...

Added textInputAction parameter to TextFormField that forwards to TextField, added onEditingComplete parameter to TextField that forwards to EditableText, added onEditingComplete parameter to TextFormField that forwards to TextField. (#19397) (#19427)
parent 865d809d
...@@ -112,6 +112,7 @@ class TextField extends StatefulWidget { ...@@ -112,6 +112,7 @@ class TextField extends StatefulWidget {
this.maxLength, this.maxLength,
this.maxLengthEnforced = true, this.maxLengthEnforced = true,
this.onChanged, this.onChanged,
this.onEditingComplete,
this.onSubmitted, this.onSubmitted,
this.inputFormatters, this.inputFormatters,
this.enabled, this.enabled,
...@@ -263,6 +264,24 @@ class TextField extends StatefulWidget { ...@@ -263,6 +264,24 @@ class TextField extends StatefulWidget {
/// Called when the text being edited changes. /// Called when the text being edited changes.
final ValueChanged<String> onChanged; final ValueChanged<String> onChanged;
/// Called when the user submits editable content (e.g., user presses the "done"
/// button on the keyboard).
///
/// The default implementation of [onEditingComplete] executes 2 different
/// behaviors based on the situation:
///
/// - When a completion action is pressed, such as "done", "go", "send", or
/// "search", the user's content is submitted to the [controller] and then
/// focus is given up.
///
/// - When a non-completion action is pressed, such as "next" or "previous",
/// the user's content is submitted to the [controller], but focus is not
/// given up because developers may want to immediately move focus to
/// another input widget within [onSubmitted].
///
/// Providing [onEditingComplete] prevents the aforementioned default behavior.
final VoidCallback onEditingComplete;
/// Called when the user indicates that they are done editing the text in the /// Called when the user indicates that they are done editing the text in the
/// field. /// field.
final ValueChanged<String> onSubmitted; final ValueChanged<String> onSubmitted;
...@@ -502,6 +521,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -502,6 +521,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
? cupertinoTextSelectionControls ? cupertinoTextSelectionControls
: materialTextSelectionControls, : materialTextSelectionControls,
onChanged: widget.onChanged, onChanged: widget.onChanged,
onEditingComplete: widget.onEditingComplete,
onSubmitted: widget.onSubmitted, onSubmitted: widget.onSubmitted,
onSelectionChanged: _handleSelectionChanged, onSelectionChanged: _handleSelectionChanged,
inputFormatters: formatters, inputFormatters: formatters,
......
...@@ -55,6 +55,7 @@ class TextFormField extends FormField<String> { ...@@ -55,6 +55,7 @@ class TextFormField extends FormField<String> {
FocusNode focusNode, FocusNode focusNode,
InputDecoration decoration = const InputDecoration(), InputDecoration decoration = const InputDecoration(),
TextInputType keyboardType = TextInputType.text, TextInputType keyboardType = TextInputType.text,
TextInputAction textInputAction = TextInputAction.done,
TextStyle style, TextStyle style,
TextAlign textAlign = TextAlign.start, TextAlign textAlign = TextAlign.start,
bool autofocus = false, bool autofocus = false,
...@@ -64,6 +65,7 @@ class TextFormField extends FormField<String> { ...@@ -64,6 +65,7 @@ class TextFormField extends FormField<String> {
bool maxLengthEnforced = true, bool maxLengthEnforced = true,
int maxLines = 1, int maxLines = 1,
int maxLength, int maxLength,
VoidCallback onEditingComplete,
ValueChanged<String> onFieldSubmitted, ValueChanged<String> onFieldSubmitted,
FormFieldSetter<String> onSaved, FormFieldSetter<String> onSaved,
FormFieldValidator<String> validator, FormFieldValidator<String> validator,
...@@ -72,6 +74,7 @@ class TextFormField extends FormField<String> { ...@@ -72,6 +74,7 @@ class TextFormField extends FormField<String> {
Brightness keyboardAppearance, Brightness keyboardAppearance,
}) : assert(initialValue == null || controller == null), }) : assert(initialValue == null || controller == null),
assert(keyboardType != null), assert(keyboardType != null),
assert(textInputAction != null),
assert(textAlign != null), assert(textAlign != null),
assert(autofocus != null), assert(autofocus != null),
assert(obscureText != null), assert(obscureText != null),
...@@ -95,6 +98,7 @@ class TextFormField extends FormField<String> { ...@@ -95,6 +98,7 @@ class TextFormField extends FormField<String> {
focusNode: focusNode, focusNode: focusNode,
decoration: effectiveDecoration.copyWith(errorText: field.errorText), decoration: effectiveDecoration.copyWith(errorText: field.errorText),
keyboardType: keyboardType, keyboardType: keyboardType,
textInputAction: textInputAction,
style: style, style: style,
textAlign: textAlign, textAlign: textAlign,
autofocus: autofocus, autofocus: autofocus,
...@@ -104,6 +108,7 @@ class TextFormField extends FormField<String> { ...@@ -104,6 +108,7 @@ class TextFormField extends FormField<String> {
maxLines: maxLines, maxLines: maxLines,
maxLength: maxLength, maxLength: maxLength,
onChanged: field.didChange, onChanged: field.didChange,
onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted, onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters, inputFormatters: inputFormatters,
enabled: enabled, enabled: enabled,
......
...@@ -168,6 +168,26 @@ void main() { ...@@ -168,6 +168,26 @@ void main() {
debugResetSemanticsIdCounter(); debugResetSemanticsIdCounter();
}); });
testWidgets('TextField passes onEditingComplete to EditableText', (WidgetTester tester) async {
final VoidCallback onEditingComplete = () {};
await tester.pumpWidget(
new MaterialApp(
home: new Material(
child: new TextField(
onEditingComplete: onEditingComplete,
),
),
),
);
final Finder editableTextFinder = find.byType(EditableText);
expect(editableTextFinder, findsOneWidget);
final EditableText editableTextWidget = tester.widget(editableTextFinder);
expect(editableTextWidget.onEditingComplete, onEditingComplete);
});
testWidgets('TextField has consistent size', (WidgetTester tester) async { testWidgets('TextField has consistent size', (WidgetTester tester) async {
final Key textFieldKey = new UniqueKey(); final Key textFieldKey = new UniqueKey();
String textFieldValue; String textFieldValue;
......
...@@ -29,6 +29,48 @@ void main() { ...@@ -29,6 +29,48 @@ void main() {
expect(textFieldWidget.textAlign, alignment); expect(textFieldWidget.textAlign, alignment);
}); });
testWidgets('Passes textInputAction to underlying TextField', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new Material(
child: new Center(
child: new TextFormField(
textInputAction: TextInputAction.next,
),
),
),
),
);
final Finder textFieldFinder = find.byType(TextField);
expect(textFieldFinder, findsOneWidget);
final TextField textFieldWidget = tester.widget(textFieldFinder);
expect(textFieldWidget.textInputAction, TextInputAction.next);
});
testWidgets('Passes onEditingComplete to underlying TextField', (WidgetTester tester) async {
final VoidCallback onEditingComplete = () {};
await tester.pumpWidget(
new MaterialApp(
home: new Material(
child: new Center(
child: new TextFormField(
onEditingComplete: onEditingComplete,
),
),
),
),
);
final Finder textFieldFinder = find.byType(TextField);
expect(textFieldFinder, findsOneWidget);
final TextField textFieldWidget = tester.widget(textFieldFinder);
expect(textFieldWidget.onEditingComplete, onEditingComplete);
});
testWidgets('onFieldSubmit callbacks are called', (WidgetTester tester) async { testWidgets('onFieldSubmit callbacks are called', (WidgetTester tester) async {
bool _called = false; bool _called = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment