Unverified Commit 1eb6a95f authored by xster's avatar xster Committed by GitHub

Pipe onsubmit for text form fields (#13687)

parent 5e2bc168
......@@ -184,6 +184,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
labelText: 'Re-type Password *',
),
obscureText: true,
onFieldSubmitted: (String value) { _handleSubmitted(); },
validator: _validatePassword,
),
),
......
......@@ -53,6 +53,7 @@ class TextFormField extends FormField<String> {
bool obscureText: false,
bool autocorrect: true,
int maxLines: 1,
ValueChanged<String> onFieldSubmitted,
FormFieldSetter<String> onSaved,
FormFieldValidator<String> validator,
List<TextInputFormatter> inputFormatters,
......@@ -82,6 +83,7 @@ class TextFormField extends FormField<String> {
autocorrect: autocorrect,
maxLines: maxLines,
onChanged: field.onChanged,
onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters,
);
},
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
......@@ -27,4 +28,25 @@ void main() {
final TextField textFieldWidget = tester.widget(textFieldFinder);
expect(textFieldWidget.textAlign, alignment);
});
testWidgets('onFieldSubmit callbacks are called', (WidgetTester tester) async {
bool _called = false;
await tester.pumpWidget(
new MaterialApp(
home: new Material(
child: new Center(
child: new TextFormField(
onFieldSubmitted: (String value) { _called = true; },
),
),
),
),
);
await tester.showKeyboard(find.byType(TextField));
tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pump();
expect(_called, true);
});
}
......@@ -106,6 +106,27 @@ class TestTextInput {
));
}
/// Simulates the user pressing one of the [TextInputAction] buttons.
/// Does not check that the [TextInputAction] performed is an acceptable one
/// based on the `inputAction` [setClientArgs].
void receiveAction(TextInputAction action) {
// Not using the `expect` function because in the case of a FlutterDriver
// test this code does not run in a package:test test zone.
if (_client == 0) {
throw new TestFailure('_client must be non-zero');
}
BinaryMessages.handlePlatformMessage(
SystemChannels.textInput.name,
SystemChannels.textInput.codec.encodeMethodCall(
new MethodCall(
'TextInputClient.performAction',
<dynamic>[_client, action.toString()],
),
),
(ByteData data) { /* response from framework is discarded */ },
);
}
/// Simulates the user hiding the onscreen keyboard.
void hide() {
_isVisible = 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