Skip to content

Commit 08209b7

Browse files
authored
Explain how to test onSubmitted in its docs (#117550)
* Explain how to test onSubmitted * Fix analyzer saying tester is undefined
1 parent 6eb002a commit 08209b7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/flutter/lib/src/widgets/editable_text.dart

+13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export 'package:flutter/services.dart' show SelectionChangedCause, SmartDashesTy
5050

5151
// Examples can assume:
5252
// late BuildContext context;
53+
// late WidgetTester tester;
5354

5455
/// Signature for the callback that reports when the user changes the selection
5556
/// (including the cursor location).
@@ -1233,6 +1234,18 @@ class EditableText extends StatefulWidget {
12331234
/// By default, [onSubmitted] is called after [onChanged] when the user
12341235
/// has finalized editing; or, if the default behavior has been overridden,
12351236
/// after [onEditingComplete]. See [onEditingComplete] for details.
1237+
///
1238+
/// ## Testing
1239+
/// The following is the recommended way to trigger [onSubmitted] in a test:
1240+
///
1241+
/// ```dart
1242+
/// await tester.testTextInput.receiveAction(TextInputAction.done);
1243+
/// ```
1244+
///
1245+
/// Sending a `LogicalKeyboardKey.enter` via `tester.sendKeyEvent` will not
1246+
/// trigger [onSubmitted]. This is because on a real device, the engine
1247+
/// translates the enter key to a done action, but `tester.sendKeyEvent` sends
1248+
/// the key to the framework only.
12361249
/// {@endtemplate}
12371250
final ValueChanged<String>? onSubmitted;
12381251

0 commit comments

Comments
 (0)